
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Javascript核心知识 · 记录技术文档内容</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="zhengyuliang">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-sectionx/sectionx.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-toggle-chapters/toggle.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="this、apply、call、bind.html" />
    
    
    <link rel="prev" href="axios知识点.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">CSS</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../CSS/18种CSS命名和书写规范.html">
            
                <a href="../CSS/18种CSS命名和书写规范.html">
            
                    
                    18种CSS命名和书写规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../CSS/灵活运用CSS开发技巧.html">
            
                <a href="../CSS/灵活运用CSS开发技巧.html">
            
                    
                    灵活运用CSS开发技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../CSS/自适应 flex grid.html">
            
                <a href="../CSS/自适应 flex grid.html">
            
                    
                    自适应 Flex Grid
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">HTML</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../HTML/浏览器里的本地数据库：IndexedDB.html">
            
                <a href="../HTML/浏览器里的本地数据库：IndexedDB.html">
            
                    
                    浏览器里的本地数据库：IndexedDB
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Vue</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../Vue/7个有用的Vue开发技巧.html">
            
                <a href="../Vue/7个有用的Vue开发技巧.html">
            
                    
                    7个有用的Vue开发技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../Vue/Vue this.$router.push、replace、go的区别.html">
            
                <a href="../Vue/Vue this.$router.push、replace、go的区别.html">
            
                    
                    Vue This.$Router.Push、Replace、Go的区别
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../Vue/Vue 的父组件和子组件生命周期钩子函数执行顺序？.html">
            
                <a href="../Vue/Vue 的父组件和子组件生命周期钩子函数执行顺序？.html">
            
                    
                    Vue 的父组件和子组件生命周期钩子函数执行顺序？
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../Vue/Vue.set和this.$set应用的场景.html">
            
                <a href="../Vue/Vue.set和this.$set应用的场景.html">
            
                    
                    Vue.Set和This.$Set应用的场景
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="../Vue/vue高级技巧.html">
            
                <a href="../Vue/vue高级技巧.html">
            
                    
                    Vue高级技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="../Vue/从 0 开始手把手带你搭建一套规范的 Vue3.x 项目工程环境.html">
            
                <a href="../Vue/从 0 开始手把手带你搭建一套规范的 Vue3.x 项目工程环境.html">
            
                    
                    从 0 开始手把手带你搭建一套规范的 Vue3.X 项目工程环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="../Vue/浅析 vue-router 源码和动态路由权限分配.html">
            
                <a href="../Vue/浅析 vue-router 源码和动态路由权限分配.html">
            
                    
                    浅析 Vue Router 源码和动态路由权限分配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="../Vue/父组件监听到子组件的生命周期.html">
            
                <a href="../Vue/父组件监听到子组件的生命周期.html">
            
                    
                    父组件监听到子组件的生命周期
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="../Vue/理解Vue.mixin，利用Vue.mixin正确的偷懒.html">
            
                <a href="../Vue/理解Vue.mixin，利用Vue.mixin正确的偷懒.html">
            
                    
                    理解Vue.Mixin，利用Vue.Mixin正确的偷懒
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">JavaScript</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="5个技巧让你更好的编写 JavaScript(ES6">
            
                <span>
            
                    
                    5个技巧让你更好的编写 JavaScript(ES6) 中条件语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="5种常见函数的写法和调用方式.html">
            
                <a href="5种常见函数的写法和调用方式.html">
            
                    
                    5种常见函数的写法和调用方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="7道javascript题，让你理解基本的javascript.html">
            
                <a href="7道javascript题，让你理解基本的javascript.html">
            
                    
                    7道Javascript题，让你理解基本的Javascript
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="Array.from(">
            
                <span>
            
                    
                    Array.From() 五个超好用的用途
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="ES6汇总资料.html">
            
                <a href="ES6汇总资料.html">
            
                    
                    ES6汇总资料
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="JS开发必须知道的41个技巧.html">
            
                <a href="JS开发必须知道的41个技巧.html">
            
                    
                    JS开发必须知道的41个技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="JavaScript之防抖Debounce和节流Throttle.html">
            
                <a href="JavaScript之防抖Debounce和节流Throttle.html">
            
                    
                    JavaScript之防抖Debounce和节流Throttle
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="JavaScript数组求并集，交集和差集.html">
            
                <a href="JavaScript数组求并集，交集和差集.html">
            
                    
                    JavaScript数组求并集，交集和差集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.9" data-path="JavaScript的优雅写法.html">
            
                <a href="JavaScript的优雅写法.html">
            
                    
                    JavaScript的优雅写法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.10" data-path="axios知识点.html">
            
                <a href="axios知识点.html">
            
                    
                    Axios知识点
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="4.11" data-path="javascript核心知识.html">
            
                <a href="javascript核心知识.html">
            
                    
                    Javascript核心知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.12" data-path="this、apply、call、bind.html">
            
                <a href="this、apply、call、bind.html">
            
                    
                    This、Apply、Call、Bind
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.13" data-path="前端js常用的60余种工具方法.html">
            
                <a href="前端js常用的60余种工具方法.html">
            
                    
                    前端Js常用的60余种工具方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.14" data-path="前端异常的捕获与处理.html">
            
                <a href="前端异常的捕获与处理.html">
            
                    
                    前端异常的捕获与处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.15" data-path="在 JavaScript 中交换值的 10 种方法.html">
            
                <a href="在 JavaScript 中交换值的 10 种方法.html">
            
                    
                    在 JavaScript 中交换值的 10 种方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.16" data-path="常用的前端JavaScript方法封装.html">
            
                <a href="常用的前端JavaScript方法封装.html">
            
                    
                    常用的前端JavaScript方法封装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.17" data-path="异步神器Async-await介绍与填坑.html">
            
                <a href="异步神器Async-await介绍与填坑.html">
            
                    
                    异步神器Async Await介绍与填坑
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.18" data-path="灵活运用JS开发技巧.html">
            
                <a href="灵活运用JS开发技巧.html">
            
                    
                    灵活运用JS开发技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.19" data-path="编写高质量可维护的代码：一目了然的注释.html">
            
                <a href="编写高质量可维护的代码：一目了然的注释.html">
            
                    
                    编写高质量可维护的代码：一目了然的注释
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.20" data-path="编写高质量可维护的代码：优化逻辑判断.html">
            
                <a href="编写高质量可维护的代码：优化逻辑判断.html">
            
                    
                    编写高质量可维护的代码：优化逻辑判断
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.21" data-path="编写高质量可维护的代码：优雅命名.html">
            
                <a href="编写高质量可维护的代码：优雅命名.html">
            
                    
                    编写高质量可维护的代码：优雅命名
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.22" data-path="编写高质量可维护的代码：数据建模.html">
            
                <a href="编写高质量可维护的代码：数据建模.html">
            
                    
                    编写高质量可维护的代码：数据建模
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Life Exp</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../life_exp/告别平庸的15个小方法.html">
            
                <a href="../life_exp/告别平庸的15个小方法.html">
            
                    
                    告别平庸的15个小方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../life_exp/日志记录.html">
            
                <a href="../life_exp/日志记录.html">
            
                    
                    日志记录
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="../life_exp/程序员的发展方向.html">
            
                <a href="../life_exp/程序员的发展方向.html">
            
                    
                    程序员的发展方向
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="../message/">
            
                <a href="../message/">
            
                    
                    Message
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Technology</li>
        
        
    
        <li class="chapter " data-level="6.1" data-path="../technology/WebSocket.html">
            
                <a href="../technology/WebSocket.html">
            
                    
                    WebSocket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="../technology/npm常用命令大全.html">
            
                <a href="../technology/npm常用命令大全.html">
            
                    
                    Npm常用命令大全
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="../technology/智能照明项目说明.html">
            
                <a href="../technology/智能照明项目说明.html">
            
                    
                    智能照明项目说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="../technology/规范化git的提交信息.html">
            
                <a href="../technology/规范化git的提交信息.html">
            
                    
                    规范化Git的提交信息
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Tutorial</li>
        
        
    
        <li class="chapter " data-level="7.1" data-path="../tutorial/Esmap地图详解.html">
            
                <a href="../tutorial/Esmap地图详解.html">
            
                    
                    Esmap地图详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="../tutorial/npm镜像切换.html">
            
                <a href="../tutorial/npm镜像切换.html">
            
                    
                    Npm镜像切换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="../tutorial/发布npm的教程.html">
            
                <a href="../tutorial/发布npm的教程.html">
            
                    
                    发布Npm的教程
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Javascript核心知识</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <html><head></head><body><div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#&#x524D;&#x7AEF;&#x8FDB;&#x9636;&#x4E4B;&#x5FC5;&#x4F1A;&#x7684;javascript&#x6280;&#x5DE7;&#x603B;&#x7ED3;"><b>1. </b>&#x524D;&#x7AEF;&#x8FDB;&#x9636;&#x4E4B;&#x5FC5;&#x4F1A;&#x7684;JavaScript&#x6280;&#x5DE7;&#x603B;&#x7ED3;</a></li><ul><li><span class="title-icon "></span><a href="#1&#x51FD;&#x6570;&#x67EF;&#x91CC;&#x5316;"><b>1.1. </b>1.&#x51FD;&#x6570;&#x67EF;&#x91CC;&#x5316;</a></li><li><span class="title-icon "></span><a href="#2&#x5173;&#x4E8E;&#x6570;&#x7EC4;"><b>1.2. </b>2.&#x5173;&#x4E8E;&#x6570;&#x7EC4;</a></li><ul><li><span class="title-icon "></span><a href="#&#x624B;&#x5199;map&#x65B9;&#x6CD5;"><b>1.2.1. </b>&#x624B;&#x5199;map&#x65B9;&#x6CD5;</a></li><li><span class="title-icon "></span><a href="#&#x624B;&#x5199;filter&#x65B9;&#x6CD5;"><b>1.2.2. </b>&#x624B;&#x5199;filter&#x65B9;&#x6CD5;</a></li><li><span class="title-icon "></span><a href="#&#x624B;&#x5199;reduce&#x65B9;&#x6CD5;"><b>1.2.3. </b>&#x624B;&#x5199;reduce&#x65B9;&#x6CD5;</a></li><li><span class="title-icon "></span><a href="#&#x624B;&#x5199;every&#x65B9;&#x6CD5;"><b>1.2.4. </b>&#x624B;&#x5199;every&#x65B9;&#x6CD5;</a></li><li><span class="title-icon "></span><a href="#&#x624B;&#x5199;some&#x65B9;&#x6CD5;"><b>1.2.5. </b>&#x624B;&#x5199;some&#x65B9;&#x6CD5;</a></li><li><span class="title-icon "></span><a href="#&#x624B;&#x5199;find&#x65B9;&#x6CD5;"><b>1.2.6. </b>&#x624B;&#x5199;find&#x65B9;&#x6CD5;</a></li><li><span class="title-icon "></span><a href="#&#x62C9;&#x5E73;&#x6570;&#x7EC4;"><b>1.2.7. </b>&#x62C9;&#x5E73;&#x6570;&#x7EC4;</a></li></ul><li><span class="title-icon "></span><a href="#3&#x56FE;&#x7247;&#x61D2;&#x52A0;&#x8F7D;--&#x60F0;&#x6027;&#x51FD;&#x6570;"><b>1.3. </b>3.&#x56FE;&#x7247;&#x61D2;&#x52A0;&#x8F7D; &amp; &#x60F0;&#x6027;&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#4&#x9884;&#x52A0;&#x8F7D;"><b>1.4. </b>4.&#x9884;&#x52A0;&#x8F7D;</a></li><li><span class="title-icon "></span><a href="#5&#x8282;&#x6D41;--&#x9632;&#x6296;"><b>1.5. </b>5.&#x8282;&#x6D41; &amp; &#x9632;&#x6296;</a></li><li><span class="title-icon "></span><a href="#6&#x5B9E;&#x73B0;new&#x5173;&#x952E;&#x5B57;"><b>1.6. </b>6.&#x5B9E;&#x73B0;new&#x5173;&#x952E;&#x5B57;</a></li><li><span class="title-icon "></span><a href="#7&#x5B9E;&#x73B0;-instanceof"><b>1.7. </b>7.&#x5B9E;&#x73B0; instanceof</a></li><li><span class="title-icon "></span><a href="#8&#x5B9E;&#x73B0;call&#xFF0C;apply&#xFF0C;bind"><b>1.8. </b>8.&#x5B9E;&#x73B0;call&#xFF0C;apply&#xFF0C;bind</a></li><li><span class="title-icon "></span><a href="#9&#x5C01;&#x88C5;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x51FD;&#x6570;"><b>1.9. </b>9.&#x5C01;&#x88C5;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#10&#x81EA;&#x8BB0;&#x5FC6;&#x51FD;&#x6570;"><b>1.10. </b>10.&#x81EA;&#x8BB0;&#x5FC6;&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#11&#x662F;&#x5426;&#x5B58;&#x5728;&#x5FAA;&#x73AF;&#x5F15;&#x7528;"><b>1.11. </b>11.&#x662F;&#x5426;&#x5B58;&#x5728;&#x5FAA;&#x73AF;&#x5F15;&#x7528;</a></li><li><span class="title-icon "></span><a href="#12&#x62F7;&#x8D1D;&#x51FD;&#x6570;"><b>1.12. </b>12.&#x62F7;&#x8D1D;&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#13promise&#x7CFB;&#x5217;"><b>1.13. </b>13.Promise&#x7CFB;&#x5217;</a></li><ul><li><span class="title-icon "></span><a href="#promiseall"><b>1.13.1. </b>Promise.all</a></li><li><span class="title-icon "></span><a href="#promiserace"><b>1.13.2. </b>Promise.race</a></li><li><span class="title-icon "></span><a href="#promsiefinally"><b>1.13.3. </b>Promsie.finally</a></li></ul><li><span class="title-icon "></span><a href="#14&#x5B9E;&#x73B0;async-await"><b>1.14. </b>14.&#x5B9E;&#x73B0;async-await</a></li><li><span class="title-icon "></span><a href="#15&#x5B9E;&#x73B0;&#x7B80;&#x6613;&#x8BA2;&#x9605;-&#x53D1;&#x5E03;"><b>1.15. </b>15.&#x5B9E;&#x73B0;&#x7B80;&#x6613;&#x8BA2;&#x9605;-&#x53D1;&#x5E03;</a></li><li><span class="title-icon "></span><a href="#16&#x5355;&#x4F8B;&#x6A21;&#x5F0F;"><b>1.16. </b>16.&#x5355;&#x4F8B;&#x6A21;&#x5F0F;</a></li><li><span class="title-icon "></span><a href="#17&#x5B9E;&#x73B0;objectcreate"><b>1.17. </b>17.&#x5B9E;&#x73B0;Object.create</a></li><li><span class="title-icon "></span><a href="#18&#x5B9E;&#x73B0;-es6-&#x7684;-class-&#x8BED;&#x6CD5;"><b>1.18. </b>18.&#x5B9E;&#x73B0; ES6 &#x7684; class &#x8BED;&#x6CD5;</a></li><li><span class="title-icon "></span><a href="#19&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;-compose-&#x51FD;&#x6570;"><b>1.19. </b>19.&#x5B9E;&#x73B0;&#x4E00;&#x4E2A; compose &#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#20&#x5B9E;&#x73B0;&#x5F02;&#x6B65;&#x5E76;&#x884C;&#x51FD;&#x6570;"><b>1.20. </b>20.&#x5B9E;&#x73B0;&#x5F02;&#x6B65;&#x5E76;&#x884C;&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#21&#x5B9E;&#x73B0;&#x5F02;&#x6B65;&#x4E32;&#x884C;&#x51FD;&#x6570;"><b>1.21. </b>21.&#x5B9E;&#x73B0;&#x5F02;&#x6B65;&#x4E32;&#x884C;&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#22&#x79C1;&#x6709;&#x53D8;&#x91CF;&#x7684;&#x5B9E;&#x73B0;"><b>1.22. </b>22.&#x79C1;&#x6709;&#x53D8;&#x91CF;&#x7684;&#x5B9E;&#x73B0;</a></li></ul></ul></div><a href="#&#x524D;&#x7AEF;&#x8FDB;&#x9636;&#x4E4B;&#x5FC5;&#x4F1A;&#x7684;javascript&#x6280;&#x5DE7;&#x603B;&#x7ED3;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><p>[TOC]</p>
<h1 id="&#x524D;&#x7AEF;&#x8FDB;&#x9636;&#x4E4B;&#x5FC5;&#x4F1A;&#x7684;javascript&#x6280;&#x5DE7;&#x603B;&#x7ED3;"><a name="&#x524D;&#x7AEF;&#x8FDB;&#x9636;&#x4E4B;&#x5FC5;&#x4F1A;&#x7684;javascript&#x6280;&#x5DE7;&#x603B;&#x7ED3;" class="anchor-navigation-ex-anchor" href="#&#x524D;&#x7AEF;&#x8FDB;&#x9636;&#x4E4B;&#x5FC5;&#x4F1A;&#x7684;javascript&#x6280;&#x5DE7;&#x603B;&#x7ED3;"><i class="fa fa-link" aria-hidden="true"></i></a>1. &#x524D;&#x7AEF;&#x8FDB;&#x9636;&#x4E4B;&#x5FC5;&#x4F1A;&#x7684;JavaScript&#x6280;&#x5DE7;&#x603B;&#x7ED3;</h1>
<h2 id="1&#x51FD;&#x6570;&#x67EF;&#x91CC;&#x5316;"><a name="1&#x51FD;&#x6570;&#x67EF;&#x91CC;&#x5316;" class="anchor-navigation-ex-anchor" href="#1&#x51FD;&#x6570;&#x67EF;&#x91CC;&#x5316;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. 1.&#x51FD;&#x6570;&#x67EF;&#x91CC;&#x5316;</h2>
<p>&#x51FD;&#x6570;&#x67EF;&#x91CC;&#x5316;&#x7684;&#x662F;&#x4E00;&#x4E2A;&#x4E3A;&#x591A;&#x53C2;&#x51FD;&#x6570;&#x5B9E;&#x73B0;&#x9012;&#x5F52;&#x964D;&#x89E3;&#x7684;&#x65B9;&#x5F0F;&#x3002;&#x5176;&#x5B9E;&#x73B0;&#x7684;&#x6838;&#x5FC3;&#x662F;:</p>
<p>1.&#x8981;&#x601D;&#x8003;&#x5982;&#x4F55;&#x7F13;&#x5B58;&#x6BCF;&#x4E00;&#x6B21;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;</p>
<p>2.&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#x548C;&#x76EE;&#x6807;&#x51FD;&#x6570;&#x7684;&#x5165;&#x53C2;&#x505A;&#x6BD4;&#x8F83;</p>
<p>&#x8FD9;&#x91CC;&#x901A;&#x8FC7;&#x95ED;&#x5305;&#x7684;&#x65B9;&#x5F0F;&#x7F13;&#x5B58;&#x53C2;&#x6570;&#xFF0C;&#x5B9E;&#x73B0;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> curry = <span class="hljs-function">(<span class="hljs-params">fn</span>) =&gt;</span> {
    <span class="hljs-keyword">let</span> params = [];
    <span class="hljs-keyword">const</span> next = <span class="hljs-function">(<span class="hljs-params">...args</span>) =&gt;</span> {
        <span class="hljs-keyword">if</span>(params.length &lt; fn.length){
            <span class="hljs-keyword">return</span> next;
        }<span class="hljs-keyword">else</span>{
            <span class="hljs-keyword">return</span> fn.apply(fn, params);
        }
    }
    <span class="hljs-keyword">return</span> next;
}
</code></pre>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> sum = <span class="hljs-function">(<span class="hljs-params">a,b,c,d</span>)=&gt;</span>{
    <span class="hljs-keyword">return</span> a + b + c + d;
}

<span class="hljs-keyword">const</span> fn=curry(sum);
<span class="hljs-keyword">const</span> res=fn(<span class="hljs-number">1</span>)(<span class="hljs-number">2</span>)(<span class="hljs-number">3</span>)(<span class="hljs-number">4</span>);
<span class="hljs-built_in">console</span>.log(res)
</code></pre>
<h2 id="2&#x5173;&#x4E8E;&#x6570;&#x7EC4;"><a name="2&#x5173;&#x4E8E;&#x6570;&#x7EC4;" class="anchor-navigation-ex-anchor" href="#2&#x5173;&#x4E8E;&#x6570;&#x7EC4;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2. 2.&#x5173;&#x4E8E;&#x6570;&#x7EC4;</h2>
<h3 id="&#x624B;&#x5199;map&#x65B9;&#x6CD5;"><a name="&#x624B;&#x5199;map&#x65B9;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#&#x624B;&#x5199;map&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2.1. &#x624B;&#x5199;map&#x65B9;&#x6CD5;</h3>
<blockquote>
<p>map()&#x65B9;&#x6CD5;&#x6839;&#x636E;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x6620;&#x5C04;&#x4E00;&#x4E2A;&#x65B0;&#x6570;&#x7EC4;</p>
</blockquote>
<pre><code class="lang-javascript"><span class="hljs-built_in">Array</span>.prototype.map = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">fn</span>)</span>{
    <span class="hljs-keyword">const</span> result = [];
    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i&lt;<span class="hljs-keyword">this</span>.length; i++){
        <span class="hljs-keyword">if</span>(!<span class="hljs-keyword">this</span>.hasOwnProperty(i)) <span class="hljs-keyword">continue</span>;
        result.push(<span class="hljs-keyword">this</span>[i], i, <span class="hljs-keyword">this</span>);
    }
    <span class="hljs-keyword">return</span> result;
}
<span class="hljs-comment">// &#x4F7F;&#x7528;</span>
<span class="hljs-keyword">const</span> arr = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,,<span class="hljs-number">5</span>];
<span class="hljs-keyword">const</span> mapArr=arr.map(<span class="hljs-function"><span class="hljs-params">item</span>=&gt;</span> item*<span class="hljs-number">2</span>);
<span class="hljs-built_in">console</span>.log(mapArr);
</code></pre>
<h3 id="&#x624B;&#x5199;filter&#x65B9;&#x6CD5;"><a name="&#x624B;&#x5199;filter&#x65B9;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#&#x624B;&#x5199;filter&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2.2. &#x624B;&#x5199;filter&#x65B9;&#x6CD5;</h3>
<blockquote>
<p>filter()&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#xFF0C;&#x8FD4;&#x56DE;&#x7684;&#x6BCF;&#x4E00;&#x9879;&#x662F;&#x5728;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x4E2D;&#x6267;&#x884C;&#x7ED3;&#x679C;true&#x3002;</p>
</blockquote>
<pre><code class="lang-javascript"><span class="hljs-built_in">Array</span>.prototype.filter = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">fn</span>)</span>{
    <span class="hljs-keyword">const</span> result = [];
    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> i=<span class="hljs-number">0</span>; i&lt;<span class="hljs-keyword">this</span>.length;i++){
        <span class="hljs-keyword">if</span>(!<span class="hljs-keyword">this</span>.hasOwnProperty(i)) <span class="hljs-keyword">continue</span>;
        fn(<span class="hljs-keyword">this</span>[i], i, <span class="hljs-keyword">this</span>) &amp;&amp; result.push(<span class="hljs-keyword">this</span>[i]);
    }
    <span class="hljs-keyword">return</span> result;
}
<span class="hljs-comment">// &#x4F7F;&#x7528;</span>
<span class="hljs-keyword">const</span> arr = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,,<span class="hljs-number">5</span>]
<span class="hljs-keyword">const</span> fliterArr=arr.filter(<span class="hljs-function"><span class="hljs-params">item</span> =&gt;</span> item &gt; <span class="hljs-number">2</span>);
<span class="hljs-built_in">console</span>.log(fliterArr);
</code></pre>
<blockquote>
<p>filter&#x548C;map&#x7684;&#x533A;&#x522B;&#xFF1A; filter&#x662F;&#x6620;&#x5C04;&#x51FA;&#x6761;&#x4EF6;&#x4E3A;true&#x7684;item&#xFF0C;map&#x662F;&#x6620;&#x5C04;&#x6BCF;&#x4E00;&#x4E2A;item&#x3002;</p>
</blockquote>
<h3 id="&#x624B;&#x5199;reduce&#x65B9;&#x6CD5;"><a name="&#x624B;&#x5199;reduce&#x65B9;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#&#x624B;&#x5199;reduce&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2.3. &#x624B;&#x5199;reduce&#x65B9;&#x6CD5;</h3>
<blockquote>
<p>reduce()&#x65B9;&#x6CD5;&#x5FAA;&#x73AF;&#x8FED;&#x4EE3;&#xFF0C;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x7684;&#x7ED3;&#x679C;&#x90FD;&#x4F1A;&#x4F5C;&#x4E3A;&#x4E0B;&#x4E00;&#x6B21;&#x7684;&#x5F62;&#x53C2;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x3002;</p>
</blockquote>
<pre><code class="lang-javascript"><span class="hljs-built_in">Array</span>.prototype.reduce = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">fn, initValue</span>) </span>{
    <span class="hljs-keyword">let</span> result = initValue ? initValue : <span class="hljs-keyword">this</span>[<span class="hljs-number">0</span>];
    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> i = initValue ? <span class="hljs-number">1</span> : <span class="hljs-number">0</span>; i &lt; <span class="hljs-keyword">this</span>.length; i++){
        <span class="hljs-keyword">if</span>(!<span class="hljs-keyword">this</span>.hasOwnProperty(i)) <span class="hljs-keyword">continue</span>;
        result=fn(result, <span class="hljs-keyword">this</span>[i],i,<span class="hljs-keyword">this</span>);
    }
    <span class="hljs-keyword">return</span> result;
}
<span class="hljs-comment">// &#x4F7F;&#x7528;</span>
<span class="hljs-keyword">const</span> arr_r=[<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,,<span class="hljs-number">5</span>]
<span class="hljs-keyword">const</span> reduceArr=arr_r.reduce(<span class="hljs-function">(<span class="hljs-params">a,b</span>) =&gt;</span> a*b, <span class="hljs-number">2</span>)
<span class="hljs-built_in">console</span>.log(reduceArr);
</code></pre>
<h3 id="&#x624B;&#x5199;every&#x65B9;&#x6CD5;"><a name="&#x624B;&#x5199;every&#x65B9;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#&#x624B;&#x5199;every&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2.4. &#x624B;&#x5199;every&#x65B9;&#x6CD5;</h3>
<blockquote>
<p>every() &#x65B9;&#x6CD5;&#x6D4B;&#x8BD5;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#x5185;&#x7684;&#x6240;&#x6709;&#x5143;&#x7D20;&#x662F;&#x5426;&#x90FD;&#x80FD;&#x901A;&#x8FC7;&#x67D0;&#x4E2A;&#x6307;&#x5B9A;&#x51FD;&#x6570;&#x7684;&#x6D4B;&#x8BD5;&#x3002;&#x5B83;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;&#x3002;</p>
</blockquote>
<pre><code class="lang-javascript"><span class="hljs-built_in">Array</span>.prototype.every = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">fn</span>) </span>{
    <span class="hljs-keyword">let</span> bool = <span class="hljs-literal">true</span>;
    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-keyword">this</span>.length; i++) {
        <span class="hljs-keyword">if</span>(!<span class="hljs-keyword">this</span>.hasOwnProperty(i)) <span class="hljs-keyword">continue</span>;
        <span class="hljs-keyword">if</span>(!fn(<span class="hljs-keyword">this</span>[i], i, <span class="hljs-keyword">this</span>)){
            bool = <span class="hljs-literal">false</span>;
            <span class="hljs-keyword">break</span>;
        }
    }
    <span class="hljs-keyword">return</span> bool;
}
<span class="hljs-comment">// &#x4F7F;&#x7528;</span>
<span class="hljs-keyword">const</span> arr_e = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,,<span class="hljs-number">5</span>];
<span class="hljs-keyword">const</span> everyArr = arr_e.every(<span class="hljs-function"><span class="hljs-params">item</span> =&gt;</span> item &gt; <span class="hljs-number">3</span>);
<span class="hljs-built_in">console</span>.log(everyArr);
</code></pre>
<h3 id="&#x624B;&#x5199;some&#x65B9;&#x6CD5;"><a name="&#x624B;&#x5199;some&#x65B9;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#&#x624B;&#x5199;some&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2.5. &#x624B;&#x5199;some&#x65B9;&#x6CD5;</h3>
<blockquote>
<p>some() &#x65B9;&#x6CD5;&#x6D4B;&#x8BD5;&#x6570;&#x7EC4;&#x4E2D;&#x662F;&#x4E0D;&#x662F;&#x81F3;&#x5C11;&#x6709;1&#x4E2A;&#x5143;&#x7D20;&#x901A;&#x8FC7;&#x4E86;&#x88AB;&#x63D0;&#x4F9B;&#x7684;&#x51FD;&#x6570;&#x6D4B;&#x8BD5;&#x3002;&#x5B83;&#x8FD4;&#x56DE;&#x7684;&#x662F;&#x4E00;&#x4E2A;Boolean&#x7C7B;&#x578B;&#x7684;&#x503C;&#x3002;</p>
</blockquote>
<pre><code class="lang-javascript"><span class="hljs-built_in">Array</span>.prototype.some = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">fn</span>) </span>{
    <span class="hljs-keyword">let</span> bool = <span class="hljs-literal">false</span>;
    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-keyword">this</span>.length; i++) {
        <span class="hljs-keyword">if</span>(!<span class="hljs-keyword">this</span>.hasOwnProperty(i)) <span class="hljs-keyword">continue</span>;
        <span class="hljs-keyword">if</span>(fn(<span class="hljs-keyword">this</span>[i], i, <span class="hljs-keyword">this</span>)) {
            bool = <span class="hljs-literal">true</span>;
            <span class="hljs-keyword">break</span>;
        }
    }
    <span class="hljs-keyword">return</span> bool;
}
<span class="hljs-comment">// &#x4F7F;&#x7528;</span>
<span class="hljs-keyword">const</span> arr_s = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,,<span class="hljs-number">5</span>];
<span class="hljs-keyword">const</span> someArr = arr_s.some(<span class="hljs-function"><span class="hljs-params">item</span> =&gt;</span> item &gt; <span class="hljs-number">3</span>);
<span class="hljs-built_in">console</span>.log(someArr);
</code></pre>
<h3 id="&#x624B;&#x5199;find&#x65B9;&#x6CD5;"><a name="&#x624B;&#x5199;find&#x65B9;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#&#x624B;&#x5199;find&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2.6. &#x624B;&#x5199;find&#x65B9;&#x6CD5;</h3>
<blockquote>
<p>find() &#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x6570;&#x7EC4;&#x4E2D;&#x6EE1;&#x8DB3;&#x63D0;&#x4F9B;&#x7684;&#x6D4B;&#x8BD5;&#x51FD;&#x6570;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x7684;&#x503C;&#x3002;&#x5426;&#x5219;&#x8FD4;&#x56DE; undefined&#x3002;</p>
</blockquote>
<pre><code class="lang-javascript"><span class="hljs-built_in">Array</span>.prototype.find = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">fn</span>) </span>{
    <span class="hljs-keyword">let</span> result;
    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-keyword">this</span>.length; i++) {
        <span class="hljs-keyword">if</span>(!<span class="hljs-keyword">this</span>.hasOwnProperty(i)) <span class="hljs-keyword">continue</span>;
        <span class="hljs-keyword">if</span>(fn(<span class="hljs-keyword">this</span>[i], i, <span class="hljs-keyword">this</span>)) {
            result = <span class="hljs-keyword">this</span>[i];
            <span class="hljs-keyword">break</span>;
        }
    }
    <span class="hljs-keyword">return</span> result;
}
<span class="hljs-comment">// &#x4F7F;&#x7528;</span>
<span class="hljs-keyword">const</span> arr_s = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,,<span class="hljs-number">5</span>];
<span class="hljs-keyword">const</span> findArr = arr_f.find(<span class="hljs-function"><span class="hljs-params">item</span> =&gt;</span> item &gt; <span class="hljs-number">6</span>);
<span class="hljs-built_in">console</span>.log(findArr);
</code></pre>
<h3 id="&#x62C9;&#x5E73;&#x6570;&#x7EC4;"><a name="&#x62C9;&#x5E73;&#x6570;&#x7EC4;" class="anchor-navigation-ex-anchor" href="#&#x62C9;&#x5E73;&#x6570;&#x7EC4;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2.7. &#x62C9;&#x5E73;&#x6570;&#x7EC4;</h3>
<blockquote>
<p>&#x5C06;&#x5D4C;&#x5957;&#x7684;&#x6570;&#x7EC4;&#x6241;&#x5E73;&#x5316;&#xFF0C;&#x5728;&#x5904;&#x7406;&#x4E1A;&#x52A1;&#x6570;&#x636E;&#x573A;&#x666F;&#x4E2D;&#x662F;&#x9891;&#x7387;&#x51FA;&#x73B0;&#x6BD4;&#x8F83;&#x9AD8;&#x7684;&#x3002;&#x90A3;&#x5982;&#x4F55;&#x5B9E;&#x73B0;&#x5462;&#xFF1F;</p>
</blockquote>
<ul>
<li>&#x5229;&#x7528;ES6&#x8BED;&#x6CD5;flat(num)&#x65B9;&#x6CD5;&#x5C06;&#x6570;&#x7EC4;&#x62C9;&#x5E73;&#x3002;</li>
</ul>
<p>&#x8BE5;&#x65B9;&#x6CD5;&#x4E0D;&#x4F20;&#x53C2;&#x6570;&#x9ED8;&#x8BA4;&#x53EA;&#x4F1A;&#x62C9;&#x5E73;&#x4E00;&#x5C42;&#xFF0C;&#x5982;&#x679C;&#x60F3;&#x62C9;&#x5E73;&#x591A;&#x5C42;&#x5D4C;&#x5957;&#x7684;&#x6570;&#x7EC4;&#xFF0C;&#x9700;&#x8981;&#x4F20;&#x5165;&#x4E00;&#x4E2A;&#x6574;&#x6570;&#xFF0C;&#x8868;&#x793A;&#x8981;&#x62C9;&#x5E73;&#x7684;&#x5C42;&#x7EA7;&#x3002;&#x8BE5;&#x8FD4;&#x56DE;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x6570;&#x7EC4;&#xFF0C;&#x5BF9;&#x539F;&#x6570;&#x7EC4;&#x6CA1;&#x6709;&#x5F71;&#x54CD;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x5229;&#x7528;flat&#x65B9;&#x6CD5;&#x5C01;&#x88C5;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">flattening</span>(<span class="hljs-params">arr, num=<span class="hljs-number">1</span></span>)</span>{
    <span class="hljs-keyword">if</span>(!<span class="hljs-built_in">Array</span>.isArray(arr)) <span class="hljs-keyword">return</span>;
    <span class="hljs-keyword">return</span> arr.flat(num)
}
</code></pre>
<ul>
<li><p>&#x5229;&#x7528;reduce()&#x65B9;&#x6CD5;&#x5C06;&#x6570;&#x7EC4;&#x62C9;&#x5E73;&#x3002;   </p>
<blockquote>
<p>&#x5229;&#x7528;reduce&#x8FDB;&#x884C;&#x8FED;&#x4EE3;&#xFF0C;&#x6838;&#x5FC3;&#x7684;&#x601D;&#x60F3;&#x662F;&#x9012;&#x5F52;&#x5B9E;&#x73B0;&#x3002;</p>
</blockquote>
</li>
</ul>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x5229;&#x7528;reduce&#x5B9E;&#x73B0;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">flattening</span>(<span class="hljs-params">arr</span>) </span>{
    <span class="hljs-keyword">if</span>(!<span class="hljs-built_in">Array</span>.isArray(arr)) <span class="hljs-keyword">return</span>;
    <span class="hljs-keyword">return</span> arr.reduce(<span class="hljs-function">(<span class="hljs-params">a,b</span>) =&gt;</span> a.concat(<span class="hljs-built_in">Array</span>.isArray(b) ? flattening(b) : a), []);
}
</code></pre>
<ul>
<li><p>&#x6A21;&#x62DF;&#x6808;&#x5B9E;&#x73B0;&#x6570;&#x7EC4;&#x62C9;&#x5E73;</p>
<blockquote>
<p>&#x8BE5;&#x65B9;&#x6CD5;&#x662F;&#x6A21;&#x62DF;&#x6808;&#xFF0C;&#x5728;&#x6027;&#x80FD;&#x4E0A;&#x76F8;&#x5BF9;&#x6700;&#x4F18;&#x89E3;&#x3002;</p>
</blockquote>
</li>
</ul>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x6808;&#x5B9E;&#x73B0;&#x62C9;&#x5E73;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">flatening</span>(<span class="hljs-params">arr</span>) </span>{
    <span class="hljs-keyword">if</span>(!<span class="hljs-built_in">Array</span>.isArray(arr)) <span class="hljs-keyword">return</span>;
    <span class="hljs-keyword">const</span> stack = [...arr];
    <span class="hljs-keyword">const</span> res = [];
    <span class="hljs-keyword">while</span>(stack.length) {
        <span class="hljs-keyword">let</span> value = stack.shift();
        <span class="hljs-built_in">Array</span>.isArray(value) ? stack.push(...value) : res.push(value)
    }
    <span class="hljs-keyword">return</span> res;
}
</code></pre>
<h2 id="3&#x56FE;&#x7247;&#x61D2;&#x52A0;&#x8F7D;--&#x60F0;&#x6027;&#x51FD;&#x6570;"><a name="3&#x56FE;&#x7247;&#x61D2;&#x52A0;&#x8F7D;--&#x60F0;&#x6027;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#3&#x56FE;&#x7247;&#x61D2;&#x52A0;&#x8F7D;--&#x60F0;&#x6027;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3. 3.&#x56FE;&#x7247;&#x61D2;&#x52A0;&#x8F7D; &amp; &#x60F0;&#x6027;&#x51FD;&#x6570;</h2>
<p>&#x5B9E;&#x73B0;&#x56FE;&#x7247;&#x61D2;&#x52A0;&#x8F7D;&#x5176;&#x6838;&#x5FC3;&#x7684;&#x601D;&#x60F3;&#x5C31;&#x662F;&#x5C06;img&#x7684;src&#x5C5E;&#x6027;&#x5148;&#x4F7F;&#x7528;&#x4E00;&#x5F20;&#x672C;&#x5730;&#x5360;&#x4F4D;&#x7B26;&#xFF0C;&#x6216;&#x8005;&#x4E3A;&#x7A7A;&#x3002;&#x7136;&#x540E;&#x771F;&#x5B9E;&#x7684;&#x56FE;&#x7247;&#x8DEF;&#x5F84;&#x518D;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;data-set&#x5C5E;&#x6027;&#x5B58;&#x8D77;&#x6765;&#xFF0C;&#x5F85;&#x8FBE;&#x5230;&#x4E00;&#x5B9A;&#x6761;&#x4EF6;&#x7684;&#x65F6;&#x5C06;data-img&#x7684;&#x5C5E;&#x6027;&#x503C;&#x8D4B;&#x7ED9;src&#x3002;</p>
<p>&#x5982;&#x4E0B;&#x662F;&#x901A;&#x8FC7;<code>scroll</code>&#x6EDA;&#x52A8;&#x4E8B;&#x4EF6;&#x76D1;&#x542C;&#x6765;&#x5B9E;&#x73B0;&#x7684;&#x56FE;&#x7247;&#x61D2;&#x52A0;&#x8F7D;&#xFF0C;&#x5F53;&#x56FE;&#x7247;&#x90FD;&#x52A0;&#x8F7D;&#x5B8C;&#x6BD5;&#x79FB;&#x9664;&#x4E8B;&#x4EF6;&#x76D1;&#x542C;&#xFF0C;&#x5E76;&#x4E14;&#x5C06;&#x79FB;&#x9664;html&#x6807;&#x7B7E;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> lazyLoad = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">imgs</span>) </span>{
    <span class="hljs-keyword">let</span> count = <span class="hljs-number">0</span>;
    <span class="hljs-keyword">const</span> deleteImgs = [];
    <span class="hljs-keyword">const</span> handler = <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
        imgs.forEach(<span class="hljs-function">(<span class="hljs-params">img, index</span>) =&gt;</span> {
            <span class="hljs-keyword">const</span> react = img.getBoundingClientRect();
            <span class="hljs-keyword">if</span>(react.top &lt; <span class="hljs-built_in">window</span>.innerHeight) {
                img.src = dataset.src;
                count++;
                deleteImgs.push(index);
                <span class="hljs-keyword">if</span>(count === imgs.length) <span class="hljs-built_in">document</span>.removeEventListener(<span class="hljs-string">&apos;scroll&apos;</span>, lazyLoad);
            }
        })
        imgs = imgs.filter(<span class="hljs-function">(<span class="hljs-params">_, index</span>) =&gt;</span> !deleteImgs.includes(index));
    }
    <span class="hljs-keyword">return</span> handler()
}
</code></pre>
<p><code>scroll</code>&#x6EDA;&#x52A8;&#x4E8B;&#x4EF6;&#x5BB9;&#x6613;&#x9020;&#x6210;&#x6027;&#x80FD;&#x95EE;&#x9898;&#x3002;&#x90A3;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>IntersectionObserver</code>&#x81EA;&#x52A8;&#x89C2;&#x5BDF;img&#x6807;&#x7B7E;&#x662F;&#x5426;&#x8FDB;&#x5165;&#x53EF;&#x89C6;&#x533A;&#x57DF;&#x3002;</p>
<p>&#x5B9E;&#x4F8B;&#x5316; IntersectionObserver &#x5B9E;&#x4F8B;&#xFF0C;&#x63A5;&#x53D7;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF1A;callback&#x662F;&#x53EF;&#x89C1;&#x6027;&#x53D8;&#x5316;&#x65F6;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF0C;option&#x662F;&#x914D;&#x7F6E;&#x5BF9;&#x8C61;&#xFF08;&#x8BE5;&#x53C2;&#x6570;&#x53EF;&#x9009;&#xFF09;&#x3002;</p>
<p>&#x5F53; img &#x6807;&#x7B7E;&#x8FDB;&#x5165;&#x53EF;&#x89C6;&#x533A;&#x57DF;&#x65F6;&#x4F1A;&#x6267;&#x884C;&#x5B9E;&#x4F8B;&#x5316;&#x65F6;&#x7684;&#x56DE;&#x8C03;&#xFF0C;&#x540C;&#x65F6;&#x7ED9;&#x56DE;&#x8C03;&#x4F20;&#x5165;&#x4E00;&#x4E2A; entries &#x53C2;&#x6570;&#xFF0C;&#x4FDD;&#x5B58;&#x7740;&#x5B9E;&#x4F8B;&#x89C2;&#x5BDF;&#x7684;&#x6240;&#x6709;&#x5143;&#x7D20;&#x7684;&#x4E00;&#x4E9B;&#x72B6;&#x6001;&#xFF0C;&#x6BD4;&#x5982;&#x6BCF;&#x4E2A;&#x5143;&#x7D20;&#x7684;&#x8FB9;&#x754C;&#x4FE1;&#x606F;&#xFF0C;&#x5F53;&#x524D;&#x5143;&#x7D20;&#x5BF9;&#x5E94;&#x7684; DOM &#x8282;&#x70B9;&#xFF0C;&#x5F53;&#x524D;&#x5143;&#x7D20;&#x8FDB;&#x5165;&#x53EF;&#x89C6;&#x533A;&#x57DF;&#x7684;&#x6BD4;&#x7387;&#xFF0C;&#x6BCF;&#x5F53;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x8FDB;&#x5165;&#x53EF;&#x89C6;&#x533A;&#x57DF;&#xFF0C;&#x5C06;&#x771F;&#x6B63;&#x7684;&#x56FE;&#x7247;&#x8D4B;&#x503C;&#x7ED9;&#x5F53;&#x524D; img &#x6807;&#x7B7E;&#xFF0C;&#x540C;&#x65F6;&#x89E3;&#x9664;&#x5BF9;&#x5176;&#x7684;&#x89C2;&#x5BDF;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> lazyLoad = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">imgs</span>) </span>{
    <span class="hljs-keyword">const</span> observer = <span class="hljs-keyword">new</span> IntersectionObserver(<span class="hljs-function">(<span class="hljs-params">entries</span>) =&gt;</span> {
        entries.forEach(<span class="hljs-function"><span class="hljs-params">entry</span> =&gt;</span> {
            <span class="hljs-keyword">if</span>(entry.intersectionRatio &gt; <span class="hljs-number">0</span>) {
                entry.target.src = dataset.src;
                observer.unobserve(entry.target);
            }
        })
    })
    imgs.forEach(<span class="hljs-function"><span class="hljs-params">img</span> =&gt;</span> observer.observe(img));
}
</code></pre>
<p>&#x5982;&#x4E0A;&#x662F;&#x61D2;&#x52A0;&#x8F7D;&#x56FE;&#x7247;&#x7684;&#x5B9E;&#x73B0;&#x65B9;&#x5F0F;&#x3002;</p>
<blockquote>
<p>&#x503C;&#x5F97;&#x601D;&#x8003;&#x7684;&#x662F;&#xFF0C;&#x61D2;&#x52A0;&#x8F7D;&#x548C;&#x60F0;&#x6027;&#x51FD;&#x6570;&#x6709;&#x4EC0;&#x4E48;&#x4E0D;&#x4E00;&#x6837;&#x561B;&#xFF1F;</p>
</blockquote>
<p>&#x6211;&#x6240;&#x7406;&#x89E3;&#x7684;&#x61D2;&#x52A0;&#x8F7D;&#x987E;&#x540D;&#x601D;&#x4E49;&#x5C31;&#x662F;&#x9700;&#x8981;&#x4E86;&#x624D;&#x53BB;&#x52A0;&#x8F7D;&#xFF0C;&#x61D2;&#x52A0;&#x8F7D;&#x6B63;&#x662F;&#x60F0;&#x6027;&#x7684;&#x4E00;&#x79CD;&#xFF0C;&#x4F46;&#x60F0;&#x6027;&#x51FD;&#x6570;&#x4E0D;&#x4EC5;&#x4EC5;&#x662F;&#x61D2;&#x52A0;&#x8F7D;&#xFF0C;&#x5B83;&#x8FD8;&#x53EF;&#x4EE5;&#x5305;&#x542B;&#x53E6;&#x5916;&#x4E00;&#x79CD;&#x65B9;&#x5411;&#x3002;</p>
<p>&#x60F0;&#x6027;&#x51FD;&#x6570;&#x7684;&#x53E6;&#x4E00;&#x79CD;&#x65B9;&#x5411;&#x662F;&#x5728;&#x91CD;&#x5199;&#x51FD;&#x6570;&#xFF0C;&#x6BCF;&#x4E00;&#x6B21;&#x8C03;&#x7528;&#x51FD;&#x6570;&#x7684;&#x65F6;&#x5019;&#x65E0;&#x9700;&#x5728;&#x505A;&#x4E00;&#x4E9B;&#x6761;&#x4EF6;&#x7684;&#x5224;&#x65AD;&#xFF0C;&#x5224;&#x65AD;&#x6761;&#x4EF6;&#x5728;&#x521D;&#x59CB;&#x5316;&#x7684;&#x65F6;&#x5019;&#x6267;&#x884C;&#x4E00;&#x6B21;&#x5C31;&#x597D;&#x4E86;&#xFF0C;&#x5373;&#x4E0B;&#x6B21;&#x5728;&#x540C;&#x6837;&#x7684;&#x6761;&#x4EF6;&#x8BED;&#x53E5;&#x4E0D;&#x9700;&#x8981;&#x518D;&#x6B21;&#x5224;&#x65AD;&#x4E86;&#xFF0C;&#x6BD4;&#x5982;&#x5728;&#x4E8B;&#x4EF6;&#x76D1;&#x542C;&#x4E0A;&#x7684;&#x517C;&#x5BB9;&#x3002;</p>
<h2 id="4&#x9884;&#x52A0;&#x8F7D;"><a name="4&#x9884;&#x52A0;&#x8F7D;" class="anchor-navigation-ex-anchor" href="#4&#x9884;&#x52A0;&#x8F7D;"><i class="fa fa-link" aria-hidden="true"></i></a>1.4. 4.&#x9884;&#x52A0;&#x8F7D;</h2>
<p>&#x9884;&#x52A0;&#x8F7D;&#x987E;&#x540D;&#x601D;&#x4E49;&#x5C31;&#x662F;&#x63D0;&#x524D;&#x52A0;&#x8F7D;&#xFF0C;&#x6BD4;&#x5982;&#x63D0;&#x524D;&#x52A0;&#x8F7D;&#x56FE;&#x7247;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> images = [...document.querySelectorAll(<span class="hljs-string">&apos;img&apos;</span>)];
<span class="hljs-keyword">const</span> loadImage = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">...imgs</span>)</span>{
    <span class="hljs-keyword">const</span> imagesArr = [];
    <span class="hljs-keyword">let</span> count = <span class="hljs-number">0</span>;
    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; imags.length; i++) {
        <span class="hljs-keyword">const</span> img = <span class="hljs-keyword">new</span> Image();
        img.onload = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            imgs[i].src = imagesArr[i];
            count++;
            <span class="hljs-keyword">if</span>(count === imagesArr.length) {
                <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x52A0;&#x8F7D;&#x5B8C;&#x6210;&apos;</span>)
            }
        }
    }
    <span class="hljs-keyword">return</span> {
        <span class="hljs-attr">setSrc</span>: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">...args</span>)</span>{
            imgs.forEach(<span class="hljs-function"><span class="hljs-params">img</span>=&gt;</span>img.src=<span class="hljs-string">&apos;///loding.png&apos;</span>);
            imagesArr = args;
        }
    }
}
</code></pre>
<p>&#x5F53;&#x7528;&#x6237;&#x9700;&#x8981;&#x67E5;&#x770B;&#x65F6;&#xFF0C;&#x53EF;&#x76F4;&#x63A5;&#x4ECE;&#x672C;&#x5730;&#x7F13;&#x5B58;&#x4E2D;&#x53D6;&#x3002;&#x9884;&#x52A0;&#x8F7D;&#x7684;&#x4F18;&#x70B9;&#x5728;&#x4E8E;&#x5982;&#x679C;&#x4E00;&#x5F20;&#x56FE;&#x7247;&#x8FC7;&#x5927;&#xFF0C;&#x90A3;&#x4E48;&#x8BF7;&#x6C42;&#x52A0;&#x8F7D;&#x56FE;&#x7247;&#x4E00;&#x5B9A;&#x4F1A;&#x6162;&#xFF0C;&#x9875;&#x9762;&#x4F1A;&#x51FA;&#x73B0;&#x7A7A;&#x767D;&#x7684;&#x73B0;&#x8C61;&#xFF0C;&#x7528;&#x6237;&#x4F53;&#x9A8C;&#x611F;&#x5C31;&#x53D8;&#x5DEE;&#x4E86;&#xFF0C;&#x4E3A;&#x4E86;&#x63D0;&#x9AD8;&#x7528;&#x6237;&#x4F53;&#x9A8C;&#xFF0C;&#x5148;&#x63D0;&#x524D;&#x52A0;&#x8F7D;&#x56FE;&#x7247;&#x5230;&#x672C;&#x5730;&#x7F13;&#x5B58;&#xFF0C;&#x5F53;&#x7528;&#x6237;&#x4E00;&#x6253;&#x5F00;&#x9875;&#x9762;&#x65F6;&#x5C31;&#x4F1A;&#x770B;&#x5230;&#x56FE;&#x7247;&#x3002;</p>
<h2 id="5&#x8282;&#x6D41;--&#x9632;&#x6296;"><a name="5&#x8282;&#x6D41;--&#x9632;&#x6296;" class="anchor-navigation-ex-anchor" href="#5&#x8282;&#x6D41;--&#x9632;&#x6296;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5. 5.&#x8282;&#x6D41; &amp; &#x9632;&#x6296;</h2>
<p>&#x9488;&#x5BF9;&#x9AD8;&#x9891;&#x7684;&#x89E6;&#x53D1;&#x7684;&#x51FD;&#x6570;&#xFF0C;&#x6211;&#x4EEC;&#x4E00;&#x822C;&#x90FD;&#x4F1A;&#x601D;&#x8003;&#x901A;&#x8FC7;&#x8282;&#x6D41;&#x6216;&#x8005;&#x9632;&#x6296;&#x53BB;&#x5B9E;&#x73B0;&#x6027;&#x80FD;&#x4E0A;&#x7684;&#x4F18;&#x5316;&#x3002;</p>
<p>&#x8282;&#x6D41;&#x5B9E;&#x73B0;&#x539F;&#x7406;&#x662F;&#x901A;&#x8FC7;&#x5B9A;&#x65F6;&#x5668;&#x4EE5;&#x548C;&#x65F6;&#x95F4;&#x5DEE;&#x505A;&#x5224;&#x65AD;&#x3002;&#x5B9A;&#x65F6;&#x5668;&#x6709;&#x5EF6;&#x8FDF;&#x7684;&#x80FD;&#x529B;&#xFF0C;&#x4E8B;&#x4EF6;&#x4E00;&#x5F00;&#x59CB;&#x4E0D;&#x4F1A;&#x7ACB;&#x5373;&#x6267;&#x884C;&#xFF0C;&#x4E8B;&#x4EF6;&#x7ED3;&#x675F;&#x540E;&#x8FD8;&#x4F1A;&#x518D;&#x6267;&#x884C;&#x4E00;&#x6B21;&#xFF1B;&#x800C;&#x65F6;&#x95F4;&#x5DEE;&#x4E8B;&#x4EF6;&#x4E00;&#x5F00;&#x59CB;&#x5C31;&#x7ACB;&#x5373;&#x6267;&#x884C;&#xFF0C;&#x65F6;&#x95F4;&#x7ED3;&#x675F;&#x4E4B;&#x540E;&#x4E5F;&#x4F1A;&#x7ACB;&#x5373;&#x505C;&#x6B62;&#x3002;</p>
<p>&#x7ED3;&#x5408;&#x4E24;&#x8005;&#x7684;&#x7279;&#x6027;&#x5C01;&#x88C5;&#x8282;&#x6D41;&#x51FD;&#x6570;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> throttle = <span class="hljs-function">(<span class="hljs-params">fn, waiting = <span class="hljs-number">1000</span>, options</span>) =&gt;</span> {
    <span class="hljs-keyword">let</span> preTime = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>(<span class="hljs-number">0</span>).getTime(),
        options = options || {
            <span class="hljs-attr">firstTime</span>: <span class="hljs-literal">true</span>,
            <span class="hljs-attr">endTime</span>: <span class="hljs-literal">false</span>,
        },
        timer;
    <span class="hljs-keyword">let</span> _throttle = <span class="hljs-function">(<span class="hljs-params">...args</span>) =&gt;</span> {
        <span class="hljs-keyword">let</span> newTime = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getTime();
        <span class="hljs-keyword">if</span>(!options.firstTime) {
            <span class="hljs-keyword">if</span>(timer) <span class="hljs-keyword">return</span>;
            timer = setTimeout(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
                fn.apply(fn, args);
                timer = <span class="hljs-literal">null</span>;
            }, waiting);
        } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (newTime - preTime &gt; waiting) {
            fn.apply(fn, args);
            preTime = newTime;
        } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (options.endTime) {
            timer = setTimeout(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
                fn.apply(fn, args);
                timer = <span class="hljs-literal">null</span>
            }, waiting);
        }
    };
    _throttle.cancel = <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
        preTime = <span class="hljs-number">0</span>;
        clearTimeout(timer);
        timer = <span class="hljs-literal">null</span>;
    };
    <span class="hljs-keyword">return</span> _throttle;
}
</code></pre>
<p>&#x51FD;&#x6570;&#x8282;&#x6D41;&#x4E0D;&#x7BA1;&#x4E8B;&#x4EF6;&#x89E6;&#x53D1;&#x6709;&#x591A;&#x9891;&#x7E41;&#xFF0C;&#x90FD;&#x4F1A;&#x4FDD;&#x8BC1;&#x5728;&#x89C4;&#x5B9A;&#x65F6;&#x95F4;&#x5185;&#x4E00;&#x5B9A;&#x4F1A;&#x6267;&#x884C;&#x4E00;&#x6B21;&#x771F;&#x6B63;&#x7684;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x51FD;&#x6570;&#x3002;</p>
<p>&#x9632;&#x6296;&#x5B9E;&#x73B0;&#x539F;&#x7406;&#x662F;&#x901A;&#x8FC7;&#x5B9A;&#x65F6;&#x5668;&#xFF0C;&#x5982;&#x679C;&#x5728;&#x89C4;&#x5B9A;&#x65F6;&#x95F4;&#x5185;&#x518D;&#x6B21;&#x89E6;&#x53D1;&#x4E8B;&#x4EF6;&#x4F1A;&#x5C06;&#x4E0A;&#x6B21;&#x7684;&#x5B9A;&#x65F6;&#x5668;&#x6E05;&#x9664;&#xFF0C;&#x5373;&#x4E0D;&#x4F1A;&#x6267;&#x884C;&#x51FD;&#x6570;&#x5E76;&#x91CD;&#x65B0;&#x8BBE;&#x7F6E;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x5B9A;&#x65F6;&#x5668;&#xFF0C;&#x76F4;&#x5230;&#x8D85;&#x8FC7;&#x89C4;&#x5B9A;&#x65F6;&#x95F4;&#x81EA;&#x52A8;&#x89E6;&#x53D1;&#x5B9A;&#x65F6;&#x5668;&#x4E2D;&#x7684;&#x51FD;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> debounce = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">fn, waiting = <span class="hljs-number">1000</span>, immediate = true</span>) </span>{
    <span class="hljs-keyword">let</span> timer, firstTime = immediate;
    <span class="hljs-keyword">let</span> _debounce = <span class="hljs-function">(<span class="hljs-params">...args</span>) =&gt;</span> {
        <span class="hljs-keyword">if</span>(timer){
            clearTimeout(timer);
            timer = <span class="hljs-literal">null</span>;
        }
        <span class="hljs-keyword">if</span>(firstTime){
            firstTime = <span class="hljs-literal">false</span>;
            fn.apply(fn, args)
        }<span class="hljs-keyword">else</span>{
            timer = setTimeout(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
                fn.apply(fn, args);
                fimer = <span class="hljs-literal">null</span>;
            }, waiting)
        }
    }
    _debounce.cancel = <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
        clearTimeout(timer);
        timer = <span class="hljs-literal">null</span>;
    }
}
</code></pre>
<h2 id="6&#x5B9E;&#x73B0;new&#x5173;&#x952E;&#x5B57;"><a name="6&#x5B9E;&#x73B0;new&#x5173;&#x952E;&#x5B57;" class="anchor-navigation-ex-anchor" href="#6&#x5B9E;&#x73B0;new&#x5173;&#x952E;&#x5B57;"><i class="fa fa-link" aria-hidden="true"></i></a>1.6. 6.&#x5B9E;&#x73B0;new&#x5173;&#x952E;&#x5B57;</h2>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> myNew = <span class="hljs-function">(<span class="hljs-params">...args</span>) =&gt;</span> {
    <span class="hljs-keyword">const</span> [fn, ...other] = args;
    <span class="hljs-keyword">const</span> target = <span class="hljs-built_in">Object</span>.create(fn.prototype);
    <span class="hljs-keyword">const</span> res = fn.apply(taret, other);
    <span class="hljs-keyword">if</span>(res &amp;&amp; (<span class="hljs-keyword">typeof</span> res === <span class="hljs-string">&apos;object&apos;</span> || <span class="hljs-keyword">typeof</span> res === <span class="hljs-string">&apos;function&apos;</span>)) {
        <span class="hljs-keyword">return</span> res;
    }
    <span class="hljs-keyword">return</span> target;
}
</code></pre>
<h2 id="7&#x5B9E;&#x73B0;-instanceof"><a name="7&#x5B9E;&#x73B0;-instanceof" class="anchor-navigation-ex-anchor" href="#7&#x5B9E;&#x73B0;-instanceof"><i class="fa fa-link" aria-hidden="true"></i></a>1.7. 7.&#x5B9E;&#x73B0; instanceof</h2>
<p>instanceof &#x8FD0;&#x7B97;&#x7B26;&#x7528;&#x4E8E;&#x68C0;&#x6D4B;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684; <code>prototype</code> &#x5C5E;&#x6027;&#x662F;&#x5426;&#x51FA;&#x73B0;&#x5728;&#x67D0;&#x4E2A;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#x94FE;&#x4E0A;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> _instanceof = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">left, right</span>) </span>{
    <span class="hljs-keyword">if</span>(!left &amp;&amp; !right) <span class="hljs-keyword">return</span>;
    <span class="hljs-keyword">const</span> rightPrototype = right.prototype;
    <span class="hljs-keyword">while</span>(left = <span class="hljs-built_in">Object</span>.getPrototypeOf(left)){
        <span class="hljs-keyword">if</span>(left === rightPrototype) <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    }
    <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
}

<span class="hljs-keyword">const</span> obj = {<span class="hljs-attr">a</span>:<span class="hljs-number">1</span>}
<span class="hljs-built_in">console</span>.log(_instanceof(obj, <span class="hljs-built_in">Object</span>));
</code></pre>
<h2 id="8&#x5B9E;&#x73B0;call&#xFF0C;apply&#xFF0C;bind"><a name="8&#x5B9E;&#x73B0;call&#xFF0C;apply&#xFF0C;bind" class="anchor-navigation-ex-anchor" href="#8&#x5B9E;&#x73B0;call&#xFF0C;apply&#xFF0C;bind"><i class="fa fa-link" aria-hidden="true"></i></a>1.8. 8.&#x5B9E;&#x73B0;call&#xFF0C;apply&#xFF0C;bind</h2>
<ul>
<li><p>call</p>
<blockquote>
<p>call&#x51FD;&#x6570;&#x5B9E;&#x73B0;&#x7684;&#x539F;&#x7406;&#x662F;&#x501F;&#x7528;&#x65B9;&#x6CD5;&#xFF0C;&#x5173;&#x952E;&#x5728;&#x4E8E;&#x9690;&#x5F0F;&#x6539;&#x53D8;<code>this</code>&#x7684;&#x6307;&#x5411;&#x3002;</p>
</blockquote>
</li>
</ul>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> _call = <span class="hljs-function">(<span class="hljs-params">...args</span>) =&gt;</span> {
    <span class="hljs-keyword">const</span> [context, ...other] = args;
    context = context ? <span class="hljs-built_in">Object</span>(context) : <span class="hljs-built_in">window</span>;
    <span class="hljs-keyword">const</span> _symbol = <span class="hljs-built_in">Symbol</span>(<span class="hljs-string">&apos;&#x7279;&#x6B8A;&#x5C5E;&#x6027;symbol&apos;</span>);
    context[_symbol] = <span class="hljs-keyword">this</span>;
    <span class="hljs-keyword">const</span> res = context[_symbol](...other);
    <span class="hljs-keyword">delete</span> context[_symbol];
    <span class="hljs-keyword">return</span> res;
}
</code></pre>
<ul>
<li><p>apply</p>
<blockquote>
<p>apply&#x51FD;&#x6570;&#x5B9E;&#x73B0;&#x7684;&#x539F;&#x7406;&#x548C;call&#x662F;&#x76F8;&#x540C;&#x7684;&#xFF0C;&#x5173;&#x952E;&#x5728;&#x4E8E;&#x53C2;&#x6570;&#x7684;&#x5904;&#x7406;&#x548C;&#x5224;&#x65AD;&#x3002;</p>
</blockquote>
</li>
</ul>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">isArrayLike</span>(<span class="hljs-params">o</span>)</span>{
    <span class="hljs-keyword">if</span>(o &amp;&amp;
       <span class="hljs-keyword">typeof</span> o === <span class="hljs-string">&apos;object&apos;</span> &amp;&amp;
       <span class="hljs-built_in">isFinite</span>(o.length) &amp;&amp;
       o.length &gt;= <span class="hljs-number">0</span> &amp;&amp;
       o.length === <span class="hljs-built_in">Math</span>.floor(o.length) &amp;&amp;
       o.length &lt; <span class="hljs-number">4294967296</span>
      ){
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    }<span class="hljs-keyword">else</span>{
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    }
}
<span class="hljs-keyword">const</span> _apply = <span class="hljs-function">(<span class="hljs-params">...args</span>) =&gt;</span> {
    <span class="hljs-keyword">const</span> [context, ...other] = args;
    context = context ? <span class="hljs-built_in">Object</span>(context) : <span class="hljs-built_in">window</span>;
    <span class="hljs-keyword">const</span> _symbol = <span class="hljs-built_in">Symbol</span>(<span class="hljs-string">&apos;&#x7279;&#x6B8A;&#x5C5E;&#x6027;&apos;</span>);
    context[_symbol] = <span class="hljs-keyword">this</span>;
    <span class="hljs-keyword">let</span> res;
    <span class="hljs-keyword">if</span>(other){
        <span class="hljs-keyword">if</span>(!<span class="hljs-built_in">Array</span>.isArray(other) &amp;&amp; !isArrayLike(other)){
            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">&apos;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x4E0D;&#x4E3A;&#x6570;&#x7EC4;&#x5E76;&#x4E14;&#x4E0D;&#x4E3A;&#x7C7B;&#x6570;&#x7EC4;&#x5BF9;&#x8C61;&#x629B;&#x51FA;&#x9519;&#x8BEF;&apos;</span>)
        }<span class="hljs-keyword">else</span>{
            res = context[_symbol](...Array.from(other));
        }
    }<span class="hljs-keyword">else</span>{
        res = context[_symbol]();
    }
    <span class="hljs-keyword">delete</span> context[_symbol];
    <span class="hljs-keyword">return</span> res;
}
</code></pre>
<blockquote>
<p>call()&#x65B9;&#x6CD5;&#x7684;&#x4F5C;&#x7528;&#x548C; apply() &#x65B9;&#x6CD5;&#x7C7B;&#x4F3C;&#xFF0C;&#x533A;&#x522B;&#x5C31;&#x662F;call()&#x65B9;&#x6CD5;&#x63A5;&#x53D7;&#x7684;&#x662F;&#x53C2;&#x6570;&#x5217;&#x8868;&#xFF0C;&#x800C;apply()&#x65B9;&#x6CD5;&#x63A5;&#x53D7;&#x7684;&#x662F;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x6570;&#x7EC4;&#x3002;</p>
</blockquote>
<ul>
<li><p>bind</p>
<blockquote>
<p>bind() &#x65B9;&#x6CD5;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x51FD;&#x6570;&#xFF0C;&#x5728; bind() &#x88AB;&#x8C03;&#x7528;&#x65F6;&#xFF0C;&#x8FD9;&#x4E2A;&#x65B0;&#x51FD;&#x6570;&#x7684; this &#x88AB;&#x6307;&#x5B9A;&#x4E3A; bind() &#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x800C;&#x5176;&#x4F59;&#x53C2;&#x6570;&#x5C06;&#x4F5C;&#x4E3A;&#x65B0;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x4F9B;&#x8C03;&#x7528;&#x65F6;&#x4F7F;&#x7528;&#x3002;</p>
</blockquote>
</li>
</ul>
<p>&#x5B9E;&#x73B0;&#x7684;&#x5173;&#x952E;&#x601D;&#x8DEF;&#xFF1A;</p>
<p>1.&#x62F7;&#x8D1D;&#x4FDD;&#x5B58;&#x539F;&#x51FD;&#x6570;&#xFF0C;&#x65B0;&#x51FD;&#x6570;&#x548C;&#x539F;&#x51FD;&#x6570;&#x539F;&#x578B;&#x94FE;&#x63A5;</p>
<p>2.&#x751F;&#x6210;&#x65B0;&#x7684;&#x51FD;&#x6570;&#xFF0C;&#x5728;&#x65B0;&#x51FD;&#x6570;&#x91CC;&#x8C03;&#x7528;&#x539F;&#x51FD;&#x6570;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">/*
 * &#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x51FD;&#x6570; 
 */</span>
<span class="hljs-keyword">const</span> _bind = <span class="hljs-function">(<span class="hljs-params">...args</span>) =&gt;</span> {
    <span class="hljs-keyword">const</span> [context, ...other] = args;
    <span class="hljs-keyword">const</span> findFn = <span class="hljs-function">(<span class="hljs-params">...params</span>) =&gt;</span> {
        context = <span class="hljs-keyword">new</span>.target ? <span class="hljs-keyword">this</span>:<span class="hljs-built_in">Object</span>(context);
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.call(context, ...args, ...params);
    }
    <span class="hljs-keyword">if</span>(<span class="hljs-keyword">this</span>.parototype) findFn.prototype = <span class="hljs-keyword">this</span>.prototype;
    <span class="hljs-keyword">return</span> findFn;
}
</code></pre>
<h2 id="9&#x5C01;&#x88C5;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x51FD;&#x6570;"><a name="9&#x5C01;&#x88C5;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#9&#x5C01;&#x88C5;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>1.9. 9.&#x5C01;&#x88C5;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x51FD;&#x6570;</h2>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> type = (<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> type = <span class="hljs-built_in">Object</span>.create(<span class="hljs-literal">null</span>);
    <span class="hljs-keyword">const</span> typeAry = [<span class="hljs-string">&apos;String&apos;</span>, <span class="hljs-string">&apos;Number&apos;</span>, <span class="hljs-string">&apos;Object&apos;</span>, <span class="hljs-string">&apos;Array&apos;</span>, <span class="hljs-string">&apos;Null&apos;</span>, <span class="hljs-string">&apos;Undefined&apos;</span>, <span class="hljs-string">&apos;Boolean&apos;</span>];
    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; typeAry.length; i++) {
        type[<span class="hljs-string">`is<span class="hljs-subst">${typeAry[i]}</span>`</span>] = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">args</span>)</span>{
            <span class="hljs-keyword">return</span> <span class="hljs-built_in">Object</span>.prototype.toString.call(args) === <span class="hljs-string">&apos;[object&apos;</span> + <span class="hljs-string">&apos;&apos;</span> + typeAry[i] + <span class="hljs-string">&apos;]&apos;</span>;
        }
    }
    <span class="hljs-keyword">return</span> type;
}())
<span class="hljs-comment">// &#x4F7F;&#x7528;</span>
<span class="hljs-built_in">console</span>.log(type.isArray({<span class="hljs-attr">a</span>:<span class="hljs-number">1</span>, <span class="hljs-attr">length</span>:<span class="hljs-number">1</span>}))
<span class="hljs-built_in">console</span>.log(type.isString(<span class="hljs-number">12</span>));
</code></pre>
<h2 id="10&#x81EA;&#x8BB0;&#x5FC6;&#x51FD;&#x6570;"><a name="10&#x81EA;&#x8BB0;&#x5FC6;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#10&#x81EA;&#x8BB0;&#x5FC6;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>1.10. 10.&#x81EA;&#x8BB0;&#x5FC6;&#x51FD;&#x6570;</h2>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x5206;&#x51FD;&#x6570;&#x4E0D;&#x540C;&#x53C2;&#x6570;&#x53D6;&#x503C;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">memory</span>(<span class="hljs-params">fn</span>) </span>{
    <span class="hljs-keyword">const</span> cache = {};
    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">...args</span>)</span>{
        <span class="hljs-keyword">const</span> key = <span class="hljs-built_in">JSON</span>.stringify(arg);
        <span class="hljs-keyword">if</span>(cache[key]) <span class="hljs-keyword">return</span> cache[key];
        cache[key] = fn.apply(fn, args);
    }
}
</code></pre>
<h2 id="11&#x662F;&#x5426;&#x5B58;&#x5728;&#x5FAA;&#x73AF;&#x5F15;&#x7528;"><a name="11&#x662F;&#x5426;&#x5B58;&#x5728;&#x5FAA;&#x73AF;&#x5F15;&#x7528;" class="anchor-navigation-ex-anchor" href="#11&#x662F;&#x5426;&#x5B58;&#x5728;&#x5FAA;&#x73AF;&#x5F15;&#x7528;"><i class="fa fa-link" aria-hidden="true"></i></a>1.11. 11.&#x662F;&#x5426;&#x5B58;&#x5728;&#x5FAA;&#x73AF;&#x5F15;&#x7528;</h2>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">cycle</span> (<span class="hljs-params">target</span>) </span>{
    <span class="hljs-keyword">var</span> map = <span class="hljs-keyword">new</span> <span class="hljs-built_in">WeakMap</span>()
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">_cycle</span> (<span class="hljs-params">obj</span>) </span>{
        <span class="hljs-keyword">if</span>(!map.has(obj)) map.set(obj, obj);
        <span class="hljs-keyword">let</span> keys = <span class="hljs-built_in">Object</span>.keys(obj);
        <span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>, len = keys.length; i &lt; len; i++){
            <span class="hljs-keyword">if</span>(<span class="hljs-keyword">typeof</span> obj[key[i]] === <span class="hljs-string">&apos;object&apos;</span>) {
                <span class="hljs-keyword">if</span>(map.has(obj[key[i]])) {
                    obj[key[i]] = <span class="hljs-string">&apos;$&apos;</span>
                    <span class="hljs-keyword">continue</span>;
                } <span class="hljs-keyword">else</span> {
                    map.set(obj[keys[i]], obj[keys[i]])
                }
                _cycle(obj[keys[i]]);
            }
        }
    }
    _cycle(target);
    <span class="hljs-keyword">return</span> target;
}
</code></pre>
<h2 id="12&#x62F7;&#x8D1D;&#x51FD;&#x6570;"><a name="12&#x62F7;&#x8D1D;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#12&#x62F7;&#x8D1D;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>1.12. 12.&#x62F7;&#x8D1D;&#x51FD;&#x6570;</h2>
<p>&#x62F7;&#x8D1D;&#x6570;&#x636E;&#x4E00;&#x76F4;&#x662F;&#x4E1A;&#x52A1;&#x5F00;&#x53D1;&#x4E2D;&#x7ED5;&#x4E0D;&#x5F00;&#x7684;&#x6280;&#x5DE7;&#xFF0C;&#x5BF9;&#x4E8E;&#x6DF1;&#x6D45;&#x62F7;&#x8D1D;&#x6570;&#x636E;&#x4E4B;&#x524D;&#x5199;&#x8FC7;&#x4E00;&#x7BC7;&#x6587;&#x7AE0;&#x6765;&#x8BB2;&#x8FF0;[&#x804A;&#x804A;&#x6DF1;&#x62F7;&#x8D1D;&#x6D45;&#x62F7;&#x8D1D;]&#x3002;</p>
<ul>
<li>&#x901A;&#x8FC7;&#x6DF1;&#x5EA6;&#x4F18;&#x5148;&#x601D;&#x7EF4;&#x62F7;&#x8D1D;&#x6570;&#x636E;&#xFF08;DFS&#xFF09;</li>
</ul>
<p>&#x6DF1;&#x5EA6;&#x4F18;&#x5148;&#x662F;&#x901A;&#x8FC7;&#x7EB5;&#x5411;&#x7684;&#x7EF4;&#x5EA6;&#x53BB;&#x601D;&#x8003;&#x95EE;&#x9898;&#xFF0C;&#x5728;&#x5904;&#x7406;&#x8FC7;&#x7A0B;&#x4E2D;&#x4E5F;&#x8003;&#x8651;&#x5230;&#x5BF9;&#x8C61;&#x73AF;&#x7684;&#x95EE;&#x9898;&#x3002;</p>
<p>&#x89E3;&#x51B3;&#x5BF9;&#x8C61;&#x73AF;&#x7684;&#x6838;&#x5FC3;&#x601D;&#x8DEF;&#x662F;&#x5148;&#x5B58;&#x518D;&#x62F7;&#x8D1D;&#x3002;&#x4E00;&#x5F00;&#x59CB;&#x5148;&#x901A;&#x8FC7;&#x4E00;&#x4E2A;&#x5BB9;&#x5668;&#x7528;&#x6765;&#x50A8;&#x5B58;&#x539F;&#x6765;&#x7684;&#x5BF9;&#x8C61;&#x518D;&#x8FDB;&#x884C;&#x62F7;&#x8D1D;&#xFF0C;&#x5728;&#x6BCF;&#x4E00;&#x6B21;&#x62F7;&#x8D1D;&#x4E4B;&#x524D;&#x53BB;&#x67E5;&#x627E;&#x5BB9;&#x5668;&#x91CC;&#x662F;&#x5426;&#x5DF2;&#x5B58;&#x5728;&#x8BE5;&#x5BF9;&#x8C61;&#x3002;&#x8FD9;&#x6837;&#x5C31;&#x5207;&#x65AD;&#x4E86;&#x539F;&#x6765;&#x7684;&#x5BF9;&#x8C61;&#x548C;&#x62F7;&#x8D1D;&#x5BF9;&#x8C61;&#x7684;&#x8054;&#x7CFB;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> DFSdeepClone = <span class="hljs-function">(<span class="hljs-params">obj, visitedArr = []</span>) =&gt;</span> {
    <span class="hljs-keyword">let</span> _obj = {};
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> obj === <span class="hljs-string">&quot;object&quot;</span> &amp;&amp; obj !== <span class="hljs-literal">null</span>) {
        <span class="hljs-keyword">let</span> index = visitedArr.indexOf(obj);
        _obj = <span class="hljs-built_in">Array</span>.isArray(obj) ? [] : {};
        <span class="hljs-keyword">if</span> (~index) {
            _obj = visitedArr[index];
        } <span class="hljs-keyword">else</span> {
            visiedArr.push(obj); <span class="hljs-comment">// &#x5148;&#x5C06;&#x539F;&#x6765;&#x4FDD;&#x5B58;&#x8D77;&#x6765;&#x5728;&#x62F7;</span>
            <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> item <span class="hljs-keyword">in</span> obj) {
                _obj[item] = DFSdeepClone(obj[item], visitedArr);
            }
        }
    } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> obj === <span class="hljs-string">&quot;function&quot;</span>) {
        _obj = <span class="hljs-built_in">eval</span>(<span class="hljs-string">&quot;(&quot;</span> + obj.toString() + <span class="hljs-string">&quot;)&quot;</span>);
    } <span class="hljs-keyword">else</span> {
        _obj = obj;
    }
    <span class="hljs-keyword">return</span> _obj;
}
</code></pre>
<ul>
<li>&#x901A;&#x8FC7;&#x5E7F;&#x5EA6;&#x4F18;&#x5148;&#x601D;&#x7EF4;&#x62F7;&#x8D1D;&#x6570;&#x636E;&#xFF08;BFS&#xFF09;</li>
</ul>
<p>&#x5E7F;&#x5EA6;&#x4F18;&#x5148;&#x662F;&#x901A;&#x8FC7;&#x6A2A;&#x5411;&#x7684;&#x7EF4;&#x5EA6;&#x53BB;&#x601D;&#x8003;&#x95EE;&#x9898;&#xFF0C;&#x901A;&#x8FC7;&#x521B;&#x9020;&#x6E90;&#x961F;&#x5217;&#x548C;&#x62F7;&#x8D1D;&#x6570;&#x7EC4;&#x961F;&#x5217;&#x4E4B;&#x95F4;&#x7684;&#x5173;&#x7CFB;&#x5B9E;&#x73B0;&#x62F7;&#x8D1D;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> BfsDeepClone = <span class="hljs-function">(<span class="hljs-params">obj</span>) =&gt;</span> {
    <span class="hljs-keyword">let</span> originObj = [obj], copyObj = [<span class="hljs-built_in">Array</span>.isArray(obj) ? [] : {}], visitedOriginArr = [], visitedCopyArr = [];
    <span class="hljs-keyword">while</span>(originObj.length &gt; <span class="hljs-number">0</span>){
        <span class="hljs-keyword">const</span> item = originObj.shift();
        <span class="hljs-keyword">const</span> _obj = copyObj.shift();
        visitedOriginArr.push(item);
        <span class="hljs-keyword">if</span>(<span class="hljs-keyword">typeof</span> item === <span class="hljs-string">&apos;object&apos;</span> &amp;&amp; item !== <span class="hljs-literal">null</span>){
            <span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> key <span class="hljs-keyword">in</span> item){
                <span class="hljs-keyword">const</span> val = item[key];
                <span class="hljs-keyword">if</span>(val.constructor === <span class="hljs-string">&apos;Object&apos;</span>){
                    <span class="hljs-keyword">const</span> index = visitedOriginArr.indexOf(item[key]);
                    <span class="hljs-keyword">if</span>(~index){
                        _obj[key] = visitedCopyArr[index];
                    }<span class="hljs-keyword">else</span>{
                        _obj[key] = {};
                        originObj.push(val);
                        copyObj.push(_obj[key]);
                    }
                }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(val.constructor === <span class="hljs-string">&apos;Array&apos;</span>){
                    _obj[key] = [];
                    originObj.push(val);
                    copyObj.push(_obj[key]);
                }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(val.constructor === <span class="hljs-string">&apos;function&apos;</span>){
                    _obj[key] = <span class="hljs-built_in">eval</span>(<span class="hljs-string">&quot;(&quot;</span> + val.toString() + <span class="hljs-string">&quot;)&quot;</span>);
                }<span class="hljs-keyword">else</span>{
                    _obj[key] = val;
                }
            }
            visitedCopyArr.push(_obj);
        }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(<span class="hljs-keyword">typeof</span> item === <span class="hljs-string">&apos;function&apos;</span>) {
            _boj = <span class="hljs-built_in">eval</span>(<span class="hljs-string">&quot;(&quot;</span> + item.toString() + <span class="hljs-string">&quot;)&quot;</span>);
        }<span class="hljs-keyword">else</span>{
            _obj = item;
        }
    }
    <span class="hljs-keyword">return</span> copyObj;
}
</code></pre>
<h2 id="13promise&#x7CFB;&#x5217;"><a name="13promise&#x7CFB;&#x5217;" class="anchor-navigation-ex-anchor" href="#13promise&#x7CFB;&#x5217;"><i class="fa fa-link" aria-hidden="true"></i></a>1.13. 13.Promise&#x7CFB;&#x5217;</h2>
<h3 id="promiseall"><a name="promiseall" class="anchor-navigation-ex-anchor" href="#promiseall"><i class="fa fa-link" aria-hidden="true"></i></a>1.13.1. Promise.all</h3>
<pre><code class="lang-javascript"><span class="hljs-built_in">Promise</span>.prototype._all = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">promiseList</span>) </span>{
    <span class="hljs-keyword">const</span> len = promiseList.length, result = [];
    <span class="hljs-keyword">let</span> count = <span class="hljs-number">0</span>;
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve, reject</span>) =&gt;</span> {
        <span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; len; i++) {
            promiseList[i]().then(<span class="hljs-function"><span class="hljs-params">res</span> =&gt;</span> {
                result[i] = res;
                count++;
                <span class="hljs-keyword">if</span>(count === len){
                    resolve(result);
                }
            }, (err) =&gt; {
                <span class="hljs-keyword">return</span> reject(err);
            })
        }
    })
}
</code></pre>
<h3 id="promiserace"><a name="promiserace" class="anchor-navigation-ex-anchor" href="#promiserace"><i class="fa fa-link" aria-hidden="true"></i></a>1.13.2. Promise.race</h3>
<pre><code class="lang-javascript"><span class="hljs-built_in">Promise</span>.prototype._race = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">promiseList</span>) </span>{
    <span class="hljs-keyword">const</span> result = [];
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve, reject</span>) =&gt;</span> {
        <span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; promiseList.length; i++){
            promiseList[i]().then(<span class="hljs-function"><span class="hljs-params">res</span> =&gt;</span> {
                <span class="hljs-keyword">return</span> resolve(res)
            }, err =&gt; {
                <span class="hljs-keyword">return</span> reject(err);
            })
        }
    })
}
</code></pre>
<h3 id="promsiefinally"><a name="promsiefinally" class="anchor-navigation-ex-anchor" href="#promsiefinally"><i class="fa fa-link" aria-hidden="true"></i></a>1.13.3. Promsie.finally</h3>
<pre><code class="lang-javascript"><span class="hljs-built_in">Promise</span>.prototype._finally = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">fn</span>)</span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.then(<span class="hljs-function"><span class="hljs-params">res</span> =&gt;</span> {
        <span class="hljs-built_in">Promise</span>.resolve(fn()).then(<span class="hljs-function"><span class="hljs-params">res</span> =&gt;</span> {
            <span class="hljs-keyword">return</span> res;
        })
    }, err =&gt; {
        <span class="hljs-built_in">Promise</span>.reject(fn()).then(<span class="hljs-function"><span class="hljs-params">err</span> =&gt;</span> {
            <span class="hljs-keyword">throw</span> err
        })
    })
}
</code></pre>
<h2 id="14&#x5B9E;&#x73B0;async-await"><a name="14&#x5B9E;&#x73B0;async-await" class="anchor-navigation-ex-anchor" href="#14&#x5B9E;&#x73B0;async-await"><i class="fa fa-link" aria-hidden="true"></i></a>1.14. 14.&#x5B9E;&#x73B0;async-await</h2>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x4E32;&#x884C;&#x8FED;&#x4EE3;--&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x4E2D;&#x95F4;&#x51FD;&#x6570;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">asyncToGenerator</span>(<span class="hljs-params">genF</span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">resolve, reject</span>) </span>{
        <span class="hljs-keyword">const</span> gen = genF(); <span class="hljs-comment">// &#x751F;&#x6210;&#x4E00;&#x4E2A;&#x8FED;&#x4EE3;&#x5668;</span>
        <span class="hljs-keyword">const</span> step = <span class="hljs-function">(<span class="hljs-params">type, args</span>) =&gt;</span> {
            <span class="hljs-keyword">let</span> next;
            <span class="hljs-keyword">try</span> {
                next = gen[type](args);
            } <span class="hljs-keyword">catch</span>(e) {
                <span class="hljs-keyword">return</span> reject(e)
            }
            <span class="hljs-keyword">const</span> { done, value } = next;
            <span class="hljs-keyword">if</span>(done) {
                <span class="hljs-keyword">return</span> resolve(value);
            }
            <span class="hljs-built_in">Promise</span>.resolve(value).then(<span class="hljs-function"><span class="hljs-params">val</span> =&gt;</span> step(<span class="hljs-string">&apos;next&apos;</span>, val), err =&gt; step(<span class="hljs-string">&apos;throw&apos;</span>, err));
        }
        step(<span class="hljs-string">&apos;next&apos;</span>);
    })
}
</code></pre>
<h2 id="15&#x5B9E;&#x73B0;&#x7B80;&#x6613;&#x8BA2;&#x9605;-&#x53D1;&#x5E03;"><a name="15&#x5B9E;&#x73B0;&#x7B80;&#x6613;&#x8BA2;&#x9605;-&#x53D1;&#x5E03;" class="anchor-navigation-ex-anchor" href="#15&#x5B9E;&#x73B0;&#x7B80;&#x6613;&#x8BA2;&#x9605;-&#x53D1;&#x5E03;"><i class="fa fa-link" aria-hidden="true"></i></a>1.15. 15.&#x5B9E;&#x73B0;&#x7B80;&#x6613;&#x8BA2;&#x9605;-&#x53D1;&#x5E03;</h2>
<pre><code class="lang-javascript"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Event</span> </span>{
    <span class="hljs-keyword">constructor</span>(){
        <span class="hljs-keyword">this</span>._event = <span class="hljs-built_in">Object</span>.create(<span class="hljs-literal">null</span>);
        <span class="hljs-keyword">this</span>.stackArr = <span class="hljs-literal">null</span>; <span class="hljs-comment">// &#x8BA2;&#x9605;&#x6570;&#x7EC4;&#xFF0C;&#x7528;&#x6765;&#x5B58;&#x653E;&#x5148;&#x53D1;&#x5E03;&#x540E;&#x8BA2;&#x9605;&#x7684;&#x6570;&#x636E;</span>
        <span class="hljs-keyword">this</span>.stackArr &amp;&amp; <span class="hljs-keyword">this</span>.stackArr.forEach(<span class="hljs-function">(<span class="hljs-params">fn, index</span>) =&gt;</span> {
            fn();
            <span class="hljs-keyword">if</span>(index === <span class="hljs-keyword">this</span>.stackArr.length - <span class="hljs-number">1</span>){
                <span class="hljs-keyword">this</span>.stackArr = <span class="hljs-literal">null</span>;
            }
        });
    }
}
Event.prototype.on = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">key, fn</span>)</span>{
    <span class="hljs-keyword">return</span> (<span class="hljs-keyword">this</span>._event[key] || <span class="hljs-keyword">this</span>._event[key]=[]).push(fn);
}
Event.prototype.emit = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">key, payload</span>)</span>{
    <span class="hljs-keyword">this</span>._event[key] &amp;&amp; <span class="hljs-keyword">this</span>._event[key].forEach(<span class="hljs-function"><span class="hljs-params">fn</span> =&gt;</span> {
        fn.call(fn, payload);
    })
    <span class="hljs-comment">// &#x7528;&#x4E00;&#x4E2A;&#x65B0;&#x51FD;&#x6570;&#x5305;&#x88F9;&#x81EA;&#x5B9A;&#x4E49;&#x7684;emit&#x51FD;&#x6570;</span>
    <span class="hljs-keyword">let</span> fn = <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> <span class="hljs-keyword">this</span>.emit.call(<span class="hljs-keyword">this</span>, key, payload);
    <span class="hljs-keyword">if</span>(!<span class="hljs-keyword">this</span>._event[key] &amp;&amp; !<span class="hljs-keyword">this</span>.stackArr) {
        <span class="hljs-keyword">this</span>.stackArr = [];
        <span class="hljs-keyword">this</span>.stackArr.push(fn);
    }
}
Event.prototype.off = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">key, callback</span>)</span>{
    <span class="hljs-keyword">if</span>(callback){
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>._event[key] = <span class="hljs-keyword">this</span>._event[key].filter(<span class="hljs-function"><span class="hljs-params">fn</span> =&gt;</span> fn != callback &amp;&amp; callback != fn.c);
    }
    <span class="hljs-keyword">this</span>._event[key] = [];
}
Event.prototype.once = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">key, fn</span>)</span>{
    <span class="hljs-keyword">const</span> one = <span class="hljs-function">(<span class="hljs-params">payload</span>) =&gt;</span> {
        fn.call(fn, payload);
        <span class="hljs-keyword">this</span>.off(key, one);
    }
    one.c = fn;
    <span class="hljs-keyword">this</span>.on(key, one);
}
Event.prototype.clearAllEvent = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-built_in">Object</span>.keys(<span class="hljs-keyword">this</span>._event).forEach(<span class="hljs-function"><span class="hljs-params">key</span> =&gt;</span> {
        <span class="hljs-keyword">this</span>._event[key] = [];
    })
}
</code></pre>
<h2 id="16&#x5355;&#x4F8B;&#x6A21;&#x5F0F;"><a name="16&#x5355;&#x4F8B;&#x6A21;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#16&#x5355;&#x4F8B;&#x6A21;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>1.16. 16.&#x5355;&#x4F8B;&#x6A21;&#x5F0F;</h2>
<p>&#x5355;&#x4F8B;&#x6A21;&#x5F0F;&#xFF1A;&#x4FDD;&#x8BC1;&#x4E00;&#x4E2A;&#x7C7B;&#x4EC5;&#x6709;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;&#xFF0C;&#x5E76;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x8BBF;&#x95EE;&#x5B83;&#x7684;&#x5168;&#x5C40;&#x8BBF;&#x95EE;&#x70B9;&#x3002;&#x5B9E;&#x73B0;&#x65B9;&#x6CD5;&#x4E00;&#x822C;&#x662F;&#x5148;&#x5224;&#x65AD;&#x5B9E;&#x4F8B;&#x662F;&#x5426;&#x5B58;&#x5728;&#xFF0C;&#x5982;&#x679C;&#x5B58;&#x5728;&#x76F4;&#x63A5;&#x8FD4;&#x56DE;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x5B58;&#x5728;&#x5C31;&#x5148;&#x521B;&#x5EFA;&#x518D;&#x8FD4;&#x56DE;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x521B;&#x5EFA;&#x5355;&#x4F8B;&#x5BF9;&#x8C61;&#xFF0C; &#x4F7F;&#x7528;&#x95ED;&#x5305;</span>
<span class="hljs-keyword">const</span> getSingle = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">fn</span>)</span>{
    <span class="hljs-keyword">let</span> result;
    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-keyword">return</span> result || (result = fn.apply(<span class="hljs-keyword">this</span>, <span class="hljs-built_in">arguments</span>))
    }
}
<span class="hljs-comment">// &#x4F7F;&#x7528;Proxy&#x62E6;&#x622A;</span>
<span class="hljs-keyword">const</span> proxy = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">fn</span>)</span>{
    <span class="hljs-keyword">let</span> result;
    <span class="hljs-keyword">const</span> handler = {
        <span class="hljs-attr">construct</span>: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-keyword">if</span>(!result){
                result = <span class="hljs-built_in">Reflect</span>.construct(fn, <span class="hljs-built_in">arguments</span>);
            }
            <span class="hljs-keyword">return</span> result;
        }
    }
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Proxy</span>(fn, handler);
}
</code></pre>
<h2 id="17&#x5B9E;&#x73B0;objectcreate"><a name="17&#x5B9E;&#x73B0;objectcreate" class="anchor-navigation-ex-anchor" href="#17&#x5B9E;&#x73B0;objectcreate"><i class="fa fa-link" aria-hidden="true"></i></a>1.17. 17.&#x5B9E;&#x73B0;Object.create</h2>
<p>Object.create()&#x65B9;&#x6CD5;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x5BF9;&#x8C61;&#xFF0C;&#x4F7F;&#x7528;&#x73B0;&#x6709;&#x7684;&#x5BF9;&#x8C61;&#x6765;&#x63D0;&#x4F9B;&#x65B0;&#x521B;&#x5EFA;&#x7684;&#x5BF9;&#x8C61;&#x7684;<strong>proto</strong>&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">Object</span>.prototype._create = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">object</span>)</span>{
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">F</span>(<span class="hljs-params"></span>)</span>{}
    F.prototype = object;
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> F();
}
</code></pre>
<p>&#x8BE5;&#x65B9;&#x6CD5;&#x662F;&#x5B9E;&#x73B0;&#x4E86;&#x5DF2;&#x6709;&#x5BF9;&#x8C61;&#x548C;&#x65B0;&#x5EFA;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#x662F;&#x4E00;&#x4E2A;&#x6D45;&#x62F7;&#x8D1D;&#x7684;&#x8FC7;&#x7A0B;&#x3002;</p>
<h2 id="18&#x5B9E;&#x73B0;-es6-&#x7684;-class-&#x8BED;&#x6CD5;"><a name="18&#x5B9E;&#x73B0;-es6-&#x7684;-class-&#x8BED;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#18&#x5B9E;&#x73B0;-es6-&#x7684;-class-&#x8BED;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.18. 18.&#x5B9E;&#x73B0; ES6 &#x7684; class &#x8BED;&#x6CD5;</h2>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fatherFn</span>(<span class="hljs-params">...arr</span>)</span>{
    <span class="hljs-keyword">this</span>.some = <span class="hljs-string">&apos;&#x7236;&#x7C7B;&#x7684;this&#x5C5E;&#x6027;&apos;</span>;
    <span class="hljs-keyword">this</span>.params = arr <span class="hljs-comment">// &#x7236;&#x7C7B;&#x7684;&#x53C2;&#x6570;</span>
}
fatherFn.prototype.fatherFnSome = <span class="hljs-string">&apos;&#x7236;&#x7C7B;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x6216;&#x8005;&#x65B9;&#x6CD5;&apos;</span>&#xFF1B;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sonFn</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">this</span>.obkoro1 = <span class="hljs-string">&apos;&#x5B50;&#x7C7B;&#x7684;this&#x5C5E;&#x6027;&apos;</span>&#xFF1B;
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">inheritPrototype</span>(<span class="hljs-params">son, father</span>) </span>{
    <span class="hljs-keyword">const</span> fatherFnPrototype = <span class="hljs-built_in">Object</span>.create(father.prototype);
    son.prototype = fatherFnPrototype; <span class="hljs-comment">// &#x8BBE;&#x7F6E;father.prototype&#x4E3A;son.prototye&#x7684;&#x539F;&#x578B;</span>
    son.prototype.constructor = son; <span class="hljs-comment">// &#x4FEE;&#x6B63;constructor &#x6307;&#x5411;</span>
    <span class="hljs-built_in">Object</span>.setPrototypeOf(son, father);
}
inheritPrototype(sonFn, fatherFn);
sonFn.prototype.sonFnSome = <span class="hljs-string">&apos;&#x5B50;&#x7C7B;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x6216;&#x8005;&#x65B9;&#x6CD5;&apos;</span>
<span class="hljs-keyword">const</span> sonFnInstance = <span class="hljs-keyword">new</span> sonFn();
</code></pre>
<p>&#x4F7F;&#x7528;Object.create()&#x65B9;&#x6CD5;&#x5C06;&#x5B50;&#x7C7B;&#x7684;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x7EE7;&#x627F;&#x4E0E;&#x7236;&#x7C7B;&#x7684;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#xFF0C;&#x901A;&#x8FC7;Object.setPrototypeOf()&#x80FD;&#x591F;&#x5B9E;&#x73B0;&#x4ECE;&#x7236;&#x7C7B;&#x4E2D;&#x7EE7;&#x627F;&#x9759;&#x6001;&#x65B9;&#x6CD5;&#x548C;&#x9759;&#x6001;&#x5C5E;&#x6027;&#x3002;</p>
<h2 id="19&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;-compose-&#x51FD;&#x6570;"><a name="19&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;-compose-&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#19&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;-compose-&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>1.19. 19.&#x5B9E;&#x73B0;&#x4E00;&#x4E2A; compose &#x51FD;&#x6570;</h2>
<p>compose&#x51FD;&#x6570;&#x662F;&#x7528;&#x6765;&#x7EC4;&#x5408;&#x5408;&#x5E76;&#x51FD;&#x6570;&#xFF0C;&#x6700;&#x540E;&#x8F93;&#x51FA;&#x503C;&#x7684;&#x601D;&#x60F3;&#x3002;&#x5728;redux&#x6E90;&#x7801;&#x4E2D;&#x7528;&#x4E8E;&#x4E2D;&#x95F4;&#x4EF6;&#x7684;&#x5904;&#x7406;&#x3002;</p>
<ul>
<li>&#x4F7F;&#x7528;while&#x5FAA;&#x73AF;&#x5B9E;&#x73B0;</li>
</ul>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">compose</span>(<span class="hljs-params">fns</span>)</span>{
    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">...args</span>)</span>{
        <span class="hljs-keyword">let</span> start = fns.length - <span class="hljs-number">1</span>;
        <span class="hljs-keyword">let</span> result = [...args];
        <span class="hljs-keyword">while</span>(start &gt;= <span class="hljs-number">0</span>){
            result = fns[start].apply(fns[start], result);
            start--;
        }
        <span class="hljs-keyword">return</span> result;
    }
}
</code></pre>
<ul>
<li>&#x4F7F;&#x7528;reduce&#x8FED;&#x4EE3;&#x5B9E;&#x73B0;</li>
</ul>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">compose</span>(<span class="hljs-params">fns</span>)</span>{
    <span class="hljs-keyword">return</span> fns.reduce(<span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> (...args) =&gt; a(b(...args)));
}
<span class="hljs-keyword">const</span> a = <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> { <span class="hljs-keyword">return</span> <span class="hljs-number">1</span> }
<span class="hljs-keyword">const</span> b = <span class="hljs-function">(<span class="hljs-params">data</span>) =&gt;</span> { <span class="hljs-keyword">return</span> data }
<span class="hljs-keyword">const</span> result = compose([a, b])();
<span class="hljs-built_in">console</span>.log(result)
</code></pre>
<h2 id="20&#x5B9E;&#x73B0;&#x5F02;&#x6B65;&#x5E76;&#x884C;&#x51FD;&#x6570;"><a name="20&#x5B9E;&#x73B0;&#x5F02;&#x6B65;&#x5E76;&#x884C;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#20&#x5B9E;&#x73B0;&#x5F02;&#x6B65;&#x5E76;&#x884C;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>1.20. 20.&#x5B9E;&#x73B0;&#x5F02;&#x6B65;&#x5E76;&#x884C;&#x51FD;&#x6570;</h2>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> asyncParallel = (...fns) {
    <span class="hljs-keyword">let</span> count = <span class="hljs-number">0</span>;
    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">...args</span>)</span>{
        <span class="hljs-keyword">const</span> [cb, ...others] = args;
        fns.forEach(<span class="hljs-keyword">async</span> fn =&gt; {
            <span class="hljs-keyword">await</span> fn.apply(fn, others);
            count++;
            <span class="hljs-keyword">if</span>(count === fns.length) cb();
        })
    }
}
</code></pre>
<h2 id="21&#x5B9E;&#x73B0;&#x5F02;&#x6B65;&#x4E32;&#x884C;&#x51FD;&#x6570;"><a name="21&#x5B9E;&#x73B0;&#x5F02;&#x6B65;&#x4E32;&#x884C;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#21&#x5B9E;&#x73B0;&#x5F02;&#x6B65;&#x4E32;&#x884C;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>1.21. 21.&#x5B9E;&#x73B0;&#x5F02;&#x6B65;&#x4E32;&#x884C;&#x51FD;&#x6570;</h2>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> asyncSerial = <span class="hljs-function">(<span class="hljs-params">...fns</span>) =&gt;</span> {
    <span class="hljs-keyword">const</span> [first, ...others] = fns;
    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">...args</span>) =&gt; </span>{
        <span class="hljs-keyword">return</span> others.reduce(<span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> <span class="hljs-built_in">Promise</span>.resolve(a()).then(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> b(...args)), first(...args));
    }
}
</code></pre>
<h2 id="22&#x79C1;&#x6709;&#x53D8;&#x91CF;&#x7684;&#x5B9E;&#x73B0;"><a name="22&#x79C1;&#x6709;&#x53D8;&#x91CF;&#x7684;&#x5B9E;&#x73B0;" class="anchor-navigation-ex-anchor" href="#22&#x79C1;&#x6709;&#x53D8;&#x91CF;&#x7684;&#x5B9E;&#x73B0;"><i class="fa fa-link" aria-hidden="true"></i></a>1.22. 22.&#x79C1;&#x6709;&#x53D8;&#x91CF;&#x7684;&#x5B9E;&#x73B0;</h2>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Calculate</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">var</span> data = <span class="hljs-keyword">new</span> <span class="hljs-built_in">WeakMap</span>();
    Calculate = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
        data.set(<span class="hljs-keyword">this</span>, <span class="hljs-built_in">Math</span>.random());
    };
    <span class="hljs-comment">// &#x65B9;&#x6CD5;&#x6302;&#x5728;&#x578B;&#x539F;&#x578B;&#x4E0A;&#xFF0C;&#x5176;&#x5B9E;&#x4F8B;&#x5171;&#x4EAB;</span>
    Calculate.prototype.doSth = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-keyword">return</span> data.get(<span class="hljs-keyword">this</span>);
    }
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Calculate();
}
<span class="hljs-keyword">let</span> c1 = <span class="hljs-keyword">new</span> Calculate();
<span class="hljs-keyword">let</span> c2 = <span class="hljs-keyword">new</span> Calculate();
<span class="hljs-built_in">console</span>.log(c1.doSth());
<span class="hljs-built_in">console</span>.log(c2.deSth());
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x662F;es5&#x5B9E;&#x73B0;&#x7684;&#x79C1;&#x6709;&#x53D8;&#x91CF;&#x7684;&#x5C01;&#x88C5;&#xFF0C;&#x901A;&#x8FC7;&#x4F7F;&#x7528;WeakMap&#x53EF;&#x4EE5;&#x6269;&#x5C55;&#x6BCF;&#x4E2A;&#x5B9E;&#x4F8B;&#x6240;&#x5BF9;&#x5E94;&#x7684;&#x79C1;&#x6709;&#x5C5E;&#x6027;&#xFF0C;&#x79C1;&#x6709;&#x5C5E;&#x6027;&#x5728;&#x5916;&#x90E8;&#x65E0;&#x6CD5;&#x88AB;&#x8BBF;&#x95EE;&#xFF0C;&#x800C;&#x4E14;&#x968F;this&#x5BF9;&#x8C61;&#x7684;&#x9500;&#x6BC1;&#x548C;&#x6D88;&#x5931;&#x3002; </p>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; zhengyuliang all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x7F16;&#x5199;&#x65F6;&#x95F4;&#xFF1A;
2021-04-16 09:42:01
</span></footer></body></html>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="axios知识点.html" class="navigation navigation-prev " aria-label="Previous page: Axios知识点">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="this、apply、call、bind.html" class="navigation navigation-next " aria-label="Next page: This、Apply、Call、Bind">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Javascript核心知识","level":"4.11","depth":1,"next":{"title":"This、Apply、Call、Bind","level":"4.12","depth":1,"path":"javaScript/this、apply、call、bind.md","ref":"javaScript/this、apply、call、bind.md","articles":[]},"previous":{"title":"Axios知识点","level":"4.10","depth":1,"path":"javaScript/axios知识点.md","ref":"javaScript/axios知识点.md","articles":[]},"dir":"ltr"},"config":{"plugins":["sectionx","splitter","tbfed-pagefooter","toggle-chapters","theme-comscore","-lunr","-search","search-plus","donate","anchor-navigation-ex","expandable-chapters","chapter-fold","expandable-chapters-small","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy zhengyuliang","modify_label":"该文件编写时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"chapter-fold":{},"pluginsConfig":{"anchor-navigation-ex":{"showLevel":false,"showGoTop":true,"isRewritePageTitle":true,"isShowTocTitleIcon":true,"tocLevel1Icon":"fa fa-hand-o-right","tocLevel2Icon":"fa fa-hand-o-right","tocLevel3Icon":"fa fa-hand-o-right"}},"livereload":{},"splitter":{},"donate":{"title":"","button":"赏","wechat":"https://gitee.com/htzyl/img_bed/raw/master/pay/weixin-min.jpg","alipay":"https://gitee.com/htzyl/img_bed/raw/master/pay/alipay-min.jpg","wechatText":"微信打赏","alipayText":"支付宝打赏"},"fontsettings":{"theme":"white","family":"sans","size":2},"sectionx":{"tag":"b"},"highlight":{},"anchor-navigation-ex":{"showLevel":true,"associatedWithSummary":true,"mode":"float","showGoTop":true,"printLog":false,"multipleH1":true,"float":{"floatIcon":"fa fa-navicon","showLevelIcon":false,"level1Icon":"","level2Icon":"","level3Icon":""},"pageTop":{"showLevelIcon":false,"level1Icon":"","level2Icon":"","level3Icon":""}},"theme-comscore":{},"expandable-chapters-small":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"toggle-chapters":{},"expandable-chapters":{},"search-plus":{}},"theme":"default","author":"zhengyuliang","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"记录技术文档内容","language":"zh-hans","gitbook":">=3.0.0","description":"记录Gitbook的配置和一些插件的使用","theme-default":{"showLevel":true}},"file":{"path":"javaScript/javascript核心知识.md","mtime":"2021-04-16T01:42:01.525Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2022-01-06T09:44:01.178Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sectionx/sectionx.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

